- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
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...
Admin
Methinks we have an IOCCC champion in our midst. Good stuff!
Admin
I applaud you. You took the wtf algorithm of thousands of lines, and compressed it into one, without actually changing the algorithm.
Admin
Actually in Java you can do:
public static byte toHex(int val) { return "0123456789ABCDEF".getBytes()[val&0xF]; }
Admin
Admin
Admin
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-|]
Admin
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
Admin
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).
Admin
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.
Admin
I think this qualafies as the Rube Goldberg Way™
Admin
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 ":"
Admin
I'm autistic, and I'd have to kill myself if I wrote something like that.
Admin
Oops, meant to put this quote in my previous reply.
Admin
How about:
char w[3]; sprintf(w, "%X", hexDigit);
Admin
Learn something about autism before insulting those of us who suffer from it. Autism DOES NOT mean we are incapable of logical thought patterns.
Admin
The "an" in front of "h" thing is something I always assumed was American. Oh well.
Admin
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.
Admin
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.
Admin
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.
Admin
Alternate name: Rube Goldberg Hex
Admin
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.
Admin
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...
Admin
Hey! It's spelled 'Brillant'!
Mike5
Admin
Great Odin's raven! :)
Admin
Agatha Christie wrote code too? You'd think someone would have mentioned that while I was learning about Turing and his pals.
Admin
A good joke, but I bet you didn't compile your code!
Admin
Commodore 64. If screen had been 32768 I would have said PET.
Admin
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...
Admin
slackjawed....
Admin
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.
Admin
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.
Admin
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".
Admin
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!
Admin
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!
Admin
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)
It's just that simple.
Admin
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 GlasgowAdmin
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!
Admin
If I'll ever get paid by the line, I'll steal this guy's Base64 encoder.
Admin
Dear Professor (H)'arry (H)'iggins...
Admin
"Oh, an hoop.<font id="Graham"> Thank you, your bleeding Highness."
</font>
Admin
He had two. Don't you understand binary? <BEG>
Sincerely,
Gene Wirchenko
Admin
Note that NUMBER_OF_ODINS_RAVENS == NUMBER_OF_HEXADECIMAL_DIGITS_PER_BYTE, so we should reuse our existing constant declaration.
</beg>
Admin
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?
Admin
B-R-I-L-L-A-N-T!!!eleven!!
Man, where did you learn your Engrish?!
Admin
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.
Admin
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....
Admin
That's made me cry with laughter.
Admin
Shouldn't that be " 'ard to port "?
Admin
Oh no, tears are falling Oh no, tears are falling, whoo oh Oh no, tears are falling, whoo oh I saw you cry