• Me (unregistered)

    b1?b2?b3?b4?F:E:b4?D:C:b3?b4?B:A:b4?9:8:b2?b3?b4:7:6:b4?5:4:b3?b4:3:2:b4?1:0

    So much shorter and simpler...

  • G (unregistered) in reply to Me
    Anonymous:
    b1?b2?b3?b4?F:E:b4?D:C:b3?b4?B:A:b4?9:8:b2?b3?b4:7:6:b4?5:4:b3?b4:3:2:b4?1:0


    Methinks we have an IOCCC champion in our midst. Good stuff!
  • (cs) in reply to Me
    Anonymous:
    b1?b2?b3?b4?F:E:b4?D:C:b3?b4?B:A:b4?9:8:b2?b3?b4:7:6:b4?5:4:b3?b4:3:2:b4?1:0

    So much shorter and simpler...


    I applaud you. You took the wtf algorithm of thousands of lines, and compressed it into one, without actually changing the algorithm.
  • smartarse (unregistered) in reply to SilverDirk

    SilverDirk:
    Oh, and in C its even more fun char toHex(int val) { return "0123456789ABCDEF"[val&0xF]; }

    Actually in Java you can do:

    public static byte toHex(int val) { return "0123456789ABCDEF".getBytes()[val&0xF]; }

     

  • slip (unregistered) in reply to lamborghini
    Alex Papadimoulis:

      /**
       * The '1' hexidecimal character.
       */

      public static final char ONE = '1';

     
    Just in case if they need to change value of 1.
  • . (unregistered) in reply to lamborghini
    Alex Papadimoulis:

      /**
       * The '1' hexidecimal character.
       */

      public static final char ONE = '1';

     
    Just in case if they need to change value of 1.
  • yet an other maintenance engineer (unregistered) in reply to unlisted_error

    Bet this code was reviewed. And no problems where found of course. It is well documented, all constants and variables conform the coding guidelines. Good code, keep up the good work. [8-|]

  • (cs) in reply to smartarse
    Anonymous:

    SilverDirk:
    Oh, and in C its even more fun char toHex(int val) { return "0123456789ABCDEF"[val&0xF]; }

    Actually in Java you can do:

    public static byte toHex(int val) { return "0123456789ABCDEF".getBytes()[val&0xF]; }

     



    I'm quite surprised no-one mentioned the Ruby Way™ to do it: your_decimal_number.to_s(16)

    want binary? -> your_decimal_number.to_s(2)
    want to reverse you hex? => your_hex_string.hex
  • Tony Morris (unregistered) in reply to smartarse
    Anonymous:

    SilverDirk:
    Oh, and in C its even more fun char toHex(int val) { return "0123456789ABCDEF"[val&0xF]; }

    Actually in Java you can do:

    public static byte toHex(int val) { return "0123456789ABCDEF".getBytes()[val&0xF]; }

     



    WTF is this attempting to achieve exactly? Aside from the dependence on the platform's locale, why does a 'toHex' method accept type int, return type byte?
    One can achieve a conversion from type int to byte with:
    final byte b = i;
    ...or if 'i' is not a constant:
    final byte b = (byte)i;
    ...so why would I invoke the hitherto 'toHex' method?

    I challenge the assertion that the original post is a one-liner in Java (for some definition of one line).
  • (cs)

    I submitted this code, so I'll add a few facts for the unbelievers.

    It's not fake.  The guy really did write this.
    There's plenty more similar (but not quite so funny) code in the piece he wrote, so I honestly believe this is his coding style.
    He wasn't paid "by the line".
    The "quality" of the code wasn't noticed for a while because it does actually work.  I only found it after the guy's contract expired, and I had the dubious honour of inheriting it.

    In fact it is this code, under discussion with another former colleague over a pint, that led me to this site. (Cheers, Tom!)

    My own solution for the convertBitsToHexadecimalCharacter method  (which has now sadly relegated the original version to the source control history files)  is included below.  It  may not be as succinct as some of the posted suggestions,  but I hope it is easily understood.

    private static char convertBitsToHexadecimalCharacter(boolean bit1,
    boolean bit2,
    boolean bit3,
    boolean bit4)
    {
    int nibble = 0;
    if (bit1) nibble |= 0x8;
    if (bit2) nibble |= 0x4;
    if (bit3) nibble |= 0x2;
    if (bit4) nibble |= 0x1;

    return "0123456789ABCDEF".charAt(nibble);
    }



  • Dustpuppy (unregistered) in reply to gonchuki
    gonchuki:

    I'm quite surprised no-one mentioned the Ruby Way™ to do it: your_decimal_number.to_s(16)

    want binary? -> your_decimal_number.to_s(2)
    want to reverse you hex? => your_hex_string.hex


    I think this qualafies as the Rube Goldberg Way™
  • Dustpuppy (unregistered) in reply to Me
    Anonymous:
    b1?b2?b3?b4?F:E:b4?D:C:b3?b4?B:A:b4?9:8:b2?b3?b4:7:6:b4?5:4:b3?b4:3:2:b4?1:0

    So much shorter and simpler...


    But wrong...
    1) Unless you previously wrote:
    #define 1 '1'
    #define 2 '2'
    ..
    #define F 'F'
    you're returning the wrong type

    2) Not sure if the logic is right, but the ending "b4:7:6:b4?5:4:b3?b4:3:2:b4?1:0" is clearly wrong  - b4 should be followed by a "?", not ":"

  • Daniel (unregistered) in reply to Pope

    I'm autistic, and I'd have to kill myself if I wrote something like that.

  • Daniel (unregistered) in reply to Pope
    Pope:

    C'mon you guys.  I got one word for you: Thorough.  That or "Autism". 

    You'd have to be one determined mutha *shut-yo-mouth* to program this. 



    Oops, meant to put this quote in my previous reply.
  • Sprezzatura (unregistered) in reply to Daniel

    How about:

    char w[3]; sprintf(w, "%X", hexDigit);

  • (cs) in reply to Pope
    Pope:

    C'mon you guys.  I got one word for you: Thorough.  That or "Autism". 

    You'd have to be one determined mutha *shut-yo-mouth* to program this. 



    Learn something about autism before insulting those of us who suffer from it. Autism DOES NOT mean we are incapable of logical thought patterns.

  • Michael Maclean (unregistered) in reply to Ytram

    The "an" in front of "h" thing is something I always assumed was American. Oh well.

  • Dan (unregistered) in reply to Ytram
    Ytram:
    cconroy:
    <font size="2">Deal Lord in Heaven.  At least it's nicely commented.  I especially like how he keeps referring to "an hexadecimal".  When did the 'h' become silent?

    </font>


    I think that is proper British english.  I'm not 100% sure, but I know I have see "an" in front of 'h' words quite a bit when reading british articles and literature.  Older english literature especially.


    I believe that it's technically proper American English, as well, especially "an hour," but also "an historian," which just sounds weird, but is correct.  Americans obviously just don't care about being correct any more (I should know, I am one), so it's disappointing to see someone get something like this right, while demonstrating utter stupidity with the code itself.
  • (cs) in reply to Pope
    Pope:

    Anonymous:
    I strongly suspect someone just wrote up a perl script to spit out that code.

    Couldn't be.  You wouldn't write comments into the script, would you?

    Oh it's possible - I've generated code which included its own comments. As a toolkit macro, its intention was to provide the programming user to generate SAS code which automatically generated views of Sybase tables - it included attributes about the tables which the user may not necessarily have been aware of, but was obtainable through looking at the meta-data. Pretty geeky, but also quite useful.

  • Peter Hodge (unregistered) in reply to VGR

    I have little doubt that somebody coded this manually.  In my first 3 years as a programmer I loved coding tools like this - so incredibly generic, useably everywhere, every letter of every line of code written neatly according to the Company Coding Standards, every block of code commented neatly (even if the comments are somewhat useless) - to the novice programmer who wrote this, it is Something Beautiful and Something to be Proud of, and was probably also a good exercise in understanding binrary / hexidecimal.  Next he or she will probably write an XML parser, then eventually one day something useful that no one has built before, and it will be incredibly organized and reliable.

    I'm still going to laugh at this code though.

  • Jon (unregistered) in reply to The Internet

    Alternate name: Rube Goldberg Hex

  • agreed (unregistered) in reply to Ytram

    yup, an example of that would be "An historical ...", though it sounds funny to me saying it out loud, it is the Queen's english.

  • (cs) in reply to agreed

    And I thought I'd never learn anything new from The Daily WTF...

    'An historian', waddayaknow, might come handy one day...

    It is a WTF anyway, though...

  • Mike5 (unregistered) in reply to Maxim
    Anonymous:
    Brilliant!

    Well... not really... he actually did 5000 LOC

    what about being paid per lines?


    Hey! It's spelled 'Brillant'!

    Mike5
  • (cs)

    Great Odin's raven! :)

  • Pooma (unregistered) in reply to Ytram
    Ytram:
    Iago:
    Ytram:

    I think that is proper British english.  I'm not 100% sure, but I know I have see "an" in front of 'h' words quite a bit when reading british articles and literature.

    Nope.  Modern British follows the same rules as American (i.e. you go by the pronunciation, "an hour" but "a hotel").  Traditionally there was a rule that where a word began with "h" and the first syllable was unaccented, then you'd write "an", so "a hospital" but "an hotel", but that is now obsolete and only used by the stuffiest pedants.  No literate Briton ever wrote "an hospital".

    As for the WTF... to think I was joking when I posted something vaguely similar in the other thread!  (Though, to be fair, this is a billion times worse than my version...)


    Yeah, most of the stuff I was basing it on was older english works, but not too terribly old.  And I would definitely call Agatha Christie a literate Brit. [;)]


    Agatha Christie wrote code too? You'd think someone would have mentioned that while I was learning about Turing and his pals.
  • Mr Compiler (unregistered) in reply to lizardfoot
    lizardfoot:
    Alex Papadimoulis:
      /**
    * The number of hexadecimal characters per byte.
    */
    public static final int NUMBER_OF_HEXADECIMAL_CHARACTERS_PER_BYTE = 2;



    This is my favorite line.  So descriptive, not only in name, but also in documentation. 


    /**
     * this is the value which helps us determine the radius of a circle
     */
    public static final int VALUE_THAT_HELPS_US_DETERMINE_THE_RADIUS_OF_A_CIRCLE = 3.14;



    A good joke, but I bet you didn't compile your code!

  • Rhialto (unregistered) in reply to WWWWolf
    WWWWolf:
    Anonymous:

    The character values don't matter... just do:

    const char hexchars[] = "012345678ABCDEF";


    Actually they did on this machine, since I was, ahem, well, I just let this one speak for itself:

    char *screen = (char *) 0x0401;

    (*(screen+4))  = hex_hi (ch[0].click);
    (*(screen+5))  = hex_low(ch[0].click);

    ... and in this architecture's case, you don't put character values to screen memory, you have to use character screen codes, which the compiler doesn't produce (or maybe it does, I didn't read all docs at that time).

    Can we guess the architecture already? Hint, few people coded in C for it =)


    Commodore 64. If screen had been 32768 I would have said PET.
  • (cs) in reply to Pooma

    Anonymous:

    Agatha Christie wrote code too? You'd think someone would have mentioned that while I was learning about Turing and his pals.

     

    Looks like you didn't read the entire message you quoted, did you? Admit it! :)

     

    The guys are arguing about proper english spelling, that's why they mention Agatha Cristie...

  • (cs)

    slackjawed....

  • ABrit (unregistered) in reply to triso
    triso:
    cconroy:
    <font size="2">Deal Lord in Heaven.  At least it's nicely commented.  I especially like how he keeps referring to "an hexadecimal".  When did the 'h' become silent?

    </font>
    <font size="5">I</font>n spoken British English a leading H is silent, hence: 'enry 'iggins, 'ermione Granger, Prince 'arry and so on.

    Well that's only if for a particular accents. As a rule, that's just plain rubbish! Cockney's (that's eastend Londoners for those of you who aren't from England) speak like that which is why Eliza Doolittle says 'enry 'iggens. But think of every British actor who is remotely well-spoken and then have a rethink.

  • ABrit (unregistered) in reply to triso
    triso:
    cconroy:
    <font size="2">Deal Lord in Heaven.  At least it's nicely commented.  I especially like how he keeps referring to "an hexadecimal".  When did the 'h' become silent?

    </font>
    <font size="5">I</font>n spoken British English a leading H is silent, hence: 'enry 'iggins, 'ermione Granger, Prince 'arry and so on.

    Well that's only if for a particular accents. As a rule, that's just plain rubbish! Cockney's (that's eastend Londoners for those of you who aren't from England) speak like that which is why Eliza Doolittle says 'enry 'iggens. But think of every British actor who is remotely well-spoken and then have a rethink.

  • (cs) in reply to triso
    triso:
    cconroy:
    <font size="2">Deal Lord in Heaven.  At least it's nicely commented.  I especially like how he keeps referring to "an hexadecimal".  When did the 'h' become silent?

    </font>
    <font size="5">I</font>n spoken British English a leading H is silent, hence: 'enry 'iggins, 'ermione Granger, Prince 'arry and so on.


    Not so, actually.  Though this is true in London and various other regional accents, the Home Counties accent (ie middle class) And RP (once famous as the standard BCC accent) pronounce (most) of the "H"s.  And, of course, the letter itself is pronounched "Haitch" rather than "Aich".
  • BritshBornAndBread (unregistered) in reply to IngramJames

    I agree with the first part completely, but not the final sentence. Nope, the letter is correctly pronounced "aitch" without the "h" sound. Check a dictionary for the phonetic spelling (the letters with wierd squiggles and spacing) and you'll see. Unfortunately, this just adds to the confusion!

  • (cs) in reply to PresidentBeef

    My personal favorite, grammatically nit-picky as it may seem, is the "ONE_BITS" constant name... :D It's like the Liars Paradox of symbol naming!

  • Kiss me, I'm Polish (unregistered) in reply to Mikademus

    The guy should have written a base abstract DecToHex class, containing a virtual ToHex() method, and then 256 inheriting classes called Dec_0_ToHex, Dec_1_ToHex, Dec_2_ToHex and so on. They would
    obviously redeclare the ToHex() method in order to return the wanted value.
    Then he should write a decision class, like (I don't know much of java, so this needs correction)

    <font size="3">class ToHex {</font>
    <font size="3">	public static string theInt;</font>
    <font size="3">	public int SetTheHex(int toWhat) {</font>
    <font size="3">		this.theInt = toWhat;</font>
    <font size="3">		return 0;</font>
    <font size="3">	}</font>
    <font size="3">	public string GetTheHex() {</font>
    <font size="3">		switch(this.theInt) {</font>
    <font size="3">			case 0:</font>
    <font size="3">				return new Dec_0_ToHex theInt.ToHex();</font>
    <font size="3">				break;
    case 1:
    return new Dec_1_ToHex theInt.ToHex();
    </font>
    <font size="3">[...]</font>
    <font size="3">			case 255:</font>
    <font size="3">				return new Dec_255_ToHex theInt.ToHex();</font>
    <font size="3">				break;</font>
    <font size="3">			default:</font>
    <font size="3">				exception e;</font>
    <font size="3">				e.exception = FILE_NOT_FOUND_EXCEPTION;</font>
    <font size="3">				throw(e);</font>
    <font size="3">		} // end switch</font>
    <font size="3">	} // end getthehex</font>
    <font size="3">} // end clas</font>s

    It's just that simple.

  • monkey (unregistered) in reply to BritshBornAndBread
    Anonymous:
    Nope, the letter is correctly pronounced "aitch" without the "h" sound.

    This is how you tell the Catholics from the Protestants

    The question in northern island used to be ‘what’s the8th letter of the alphabet?'

    Variation on “what football team do you support?” in Glasgow
  • monkey (unregistered) in reply to monkey

    ireland!!

    screw writing properly

    this is why i'm a coder - very limited number of words

    SQL is a favouite what with effectively only 4 words, no I never DROP or TRUNCATE anything or even join tables.

    reminds me of an applicant we had for a job who was sent by an agency specifically because we needed someone with good SQL.  At interview when asked about OUTER JOINs explained that he had never needed to join 2 tables togeather and asked why you might want to do so!

  • (cs)

    If I'll ever get paid by the line, I'll steal this guy's Base64 encoder.

  • George (unregistered) in reply to cconroy

    cconroy:
    <FONT size=2>Deal Lord in Heaven.  At least it's nicely commented.  I especially like how he keeps referring to "an hexadecimal".  When did the 'h' become silent?

    </FONT>

    Dear Professor (H)'arry  (H)'iggins... 

  • (cs) in reply to George

    "Oh, an hoop.<font id="Graham"> Thank you, your bleeding Highness."
    </font>

  • (cs) in reply to elwood_j_blues
    elwood_j_blues:
    Great Odin's raven! :)


    He had two.  Don't you understand binary? <BEG>

    Sincerely,

    Gene Wirchenko

  • (cs) in reply to Gene Wirchenko
    Gene Wirchenko:
    elwood_j_blues:
    Great Odin's raven! :)


    He had two.  Don't you understand binary? <beg>

    Sincerely,

    Gene Wirchenko



    Note that NUMBER_OF_ODINS_RAVENS == NUMBER_OF_HEXADECIMAL_DIGITS_PER_BYTE, so we should reuse our existing constant declaration.
    </beg>
  • John Hensley (unregistered) in reply to dharbige
    dharbige:
    I submitted this code, so I'll add a few facts for the unbelievers.

    It's not fake.  The guy really did write this.
    There's plenty more similar (but not quite so funny) code in the piece he wrote, so I honestly believe this is his coding style.
    He wasn't paid "by the line".
    The "quality" of the code wasn't noticed for a while because it does actually work.  I only found it after the guy's contract expired, and I had the dubious honour of inheriting it.

    If the guy wasn't paid by the line, that makes it all the more unbelievable. This isn't "style," it's mental illness.

    Did you do a performance comparison after replacing the code?

  • Paula (unregistered) in reply to Maxim
    Anonymous:
    Brilliant!

    B-R-I-L-L-A-N-T!!!eleven!!
    Man, where did you learn your Engrish?!
  • John Hensley (unregistered) in reply to Lissa
    Lissa:

    Learn something about autism before insulting those of us who suffer from it. Autism DOES NOT mean we are incapable of logical thought patterns.

    DSM-IV lists preoccupation with repeating patterns as an indication of autism. If that's an insult, complain to the APA.

    Anyone in the US who, during the past 15 years, was diagnosed with autism while attending public schools, and was handled specially as a result, should be intensely skeptical of the diagnosis. I'm the son of a public school teacher and I can tell you that psychology has become completely politicized in that system.

    Sorry for the off-topicness, but I see a lot of autism-spectrum talk among intelligent young programmers lately, some of whom react very negatively when you suggest that they might be misdiagnosed. They seem to turn to the diagnosis as a form of self-therapy and I can scarcely imagine how angry they'd be if they knew how deep the institutional rot goes.

  • A Joke (unregistered) in reply to apaq11

    You have got to be fucking kidding...the only way I believe this is real is becuase I know Alex or the subbmitter wouldn't waste so much time writing such a waste of time....

  • Who Me? (unregistered) in reply to Digitalbath
    Digitalbath:

    Ytram:
    cconroy:
    <font size="2">Deal Lord in Heaven.  At least it's nicely commented.  I especially like how he keeps referring to "an hexadecimal".  When did the 'h' become silent?

    </font>


    I think that is proper British english.  I'm not 100% sure, but I know I have see "an" in front of 'h' words quite a bit when reading british articles and literature.  Older english literature especially.

    Maybe he was speaking in pirate.  "An 'exidecimal is upon us, ye lads.  Hard to port!" 

    Maybe not...it was funny in my head though.



    That's made me cry with laughter.
  • Your Name (unregistered) in reply to Digitalbath
    Digitalbath:

    Maybe he was speaking in pirate.  "An 'exidecimal is upon us, ye lads.  Hard to port!" 

    Maybe not...it was funny in my head though.



    Shouldn't that be " 'ard to port "?

  • Your Name (unregistered)

    Oh no, tears are falling Oh no, tears are falling, whoo oh Oh no, tears are falling, whoo oh I saw you cry

Leave a comment on “To the Hexth Degree”

Log In or post as a guest

Replying to comment #:

« Return to Article