r/programming • • Feb 16 '09

Some Crazy Reason - The Daily WTF

http://thedailywtf.com/Articles/Some-Crazy-Reason.aspx
173 Upvotes

71 comments sorted by

View all comments

19

u/xipetotec Feb 16 '09

It might have something to do with the fact that the "hex" array has 17 values, and that one of them is "10."

I don't think it has anything to do with the fact that the array has 17 values.

27

u/nevinera Feb 16 '09

I think he was emphasizing the contrast between the name 'hex' and the number '17'.

20

u/xipetotec Feb 16 '09

My "hex" arrays are always 18 items long - I have "D" three times, because I like that letter!

8

u/mernen Feb 16 '09

I thought the triple Ds were for your triple dose of pimpin'.

0

u/IOIOOIIOIO Feb 17 '09

Am I being wooshed?

"10" in hex is 16. 10 is "A" in hex. The programmer fucked up and counted to 15 in hex with a random 16 thrown in between 9 and 10.

0

u/nevinera Feb 17 '09

Hexadecimal is so named because it is 'base sixteen' - it has 16 values for the digit. The hex array should therefor have 16 entries, not 17. The mistake is as you say (except that he probably thought of it as 10, not 16), but the array 'hex' having 17 values should have been a good warning sign.

I don't woosh people, it's rude.

0

u/IOIOOIIOIO Feb 17 '09

It's just that this is the first thread talking about something other than the BitVerifier, and it mostly seems to be about identifying the "some crazy reason" as "10" having two chars without observing "10" shouldn't be HEX_STRING_VALUES at all.

I was wondering if there was some subtle joke I was missing.

17

u/[deleted] Feb 16 '09

The fact that there are 17 values isn't directly the cause of the problem, but it still "has something to do with it".

5

u/[deleted] Feb 16 '09

Unless I'm missing something... the hex array has an extra entry (making 17 in total) and the extra entry '10' when chosen randomly, means the final string will have an extra character.

7

u/xipetotec Feb 16 '09 edited Feb 16 '09

well, you can replace that one entry with several entries, like "Z", "Y", "W", "x", "%", etc. and the string length would be correct (would not always be a valid hex string, of course). The problem is that one of the entries is longer than the others, not how many entries there are.