- 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
This system is ahead of its time. Negative quantum information was just recently discovered(http://www.physorg.com/news5621.html) and yet this system already has a -1 value for hex2dec!
Admin
You gotta love hex2dec("11") returning -1. Option Explicit wouldn't hurth either.
Admin
What? no dec2hex() or bin2hex()?
Admin
And I always tought that computers numbers were binary.
Admin
I love the consistency in error case return values. -1 for one, 2222 for the other. I guess -1-1-1-1 wouldn't work.
Admin
-4?
Admin
Brillant!
Sorry...someone had to say it...
Admin
This is problematic. I'm sure the lexical parser layer in the system would reduce -1-1-1-1 to (-1 * -1) * (-1 * -1) which is, of course, 1 - and 1 is plainly not the correct result. Therefore 2 is the only genuine option. Besides, everyone knows that 2 is an impossible number, so this function absolutely cannot ever fail!
Brillant.
Admin
That one will live on for quite a while. Thanks Paula!
Admin
If you buy into the "Joel on Software: I hate exceptions" approach, this is prefectly good code.
And we all know that everywhere these methods are being called, the caller is checking that the value is not 2222 or -1 respectively.
Admin
as far as i'm concerned, the second function is perfectly valid. -1 is a value that cannot be stored in a hex digit, and is a good way to return an error. sure, the author was a bit daft, but i wouldn't call security to escort him out of the building if i saw it in my codebase.
the first function, on the other hand, subscribes to the theory of "if i find an error, i'll just silently introduce more errors into the data". deserving of a reprimand, but still not a fireable offence. i just hope the fucker who wrote this is not making more than i am.
Admin
Alright, I know what the WTF is here... not only does this code not handle lowercase letters, but it doesn't do uppercase numbers either!
Admin
You know, when I was doing classic WTF week, I wanted to repost the Paula Bean one. That was one of my favorites ever, it just seemed too soon and people were already bitching about reposts.
Admin
luckily my life exists with the bounds of [0,15]
Admin
No doubt that was an instant classic.
Admin
hex2dec("11") would be bad. If that's the way the code is being used. But, it might instead be being used like this:
(and, sorry, I don't know visual basic; using perl)
Of course, if that were the case, I would expect that instead of "hex2dec", the submitted code would be called something like "hexdigit2decdigit", and then the above code would be called "hex2dec" instead of "some_larger_routine".
And that still leaves the nature of how errors are being handled.
Admin
Ugh. Why does the "preview" button show things as though it's html formatted, when the final post doesn't require html formatting? I think that's a WTF right there.
Admin
I don't see why -1 is a better return code than 2222. 2222 cannot be stored in a hex digit either. Perhaps from a convention standpoint it's better but not fundamentally.
Admin
This has already been posted. Try the seach tool.
Admin
<FONT face="Courier New" size=2>WRONG, WRONG, WRONG! didn't he read the spec? these functions are supposed to return "Z"!</FONT>
Admin
Now *that* is brilliant!
-ds
Admin
You can hope all you want, but given the other "code" that have been introduced as code examples of consultants, I bet he's got a porsche.
Admin
Especially the unorthodox spelling of 'search'.
Admin
Well, it depends on your machine. If you were using 8 bit words -1 has hex value FF. For 16 bit words, the value is FFFF. For a 64 bit machine it is FFFF FFFF FFFF FFFF. And that's just the tip of the problem. I don't even want to go into Big vs Little Endian. For the binary, do we know if its one's compliment or two's
Admin
The world is full of enough discord without this kind of bigotry. Please, try to keep it professional.
Admin
Bender: Whoa, what an awful dream. Ones and zeros everywhere. And I thought I saw a two. Fry: It was just a dream, Bender. There's no such thing as two.
Admin
I've seen all sorts of math libraries which overcome the CPU's integer limitation in order to process very large numbers and different bases... precisely.
However, this string conversion crap... what useful purpose could it possibly serve? Unless maybe this is part of some sort of silly scheme to accompish BinHex encoding?
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemconvertclasstobase64stringtopic.asp
Admin
Those are called "heavy endian" and "vertically challenged endian" these days.
Admin
How does hex digit B convert to *a* decimal digit?
If you are going to be pedantic, it is best to be correctly pedantic. Otherwise, the effect is lost.
Sincerely,
Gene Wirchenko
Admin
De Ja Vu?
Admin
-1 is an integer. When a function that's supposed to return a positive integer returns a negative one, you know something went wrong. This is a common convention in many of the UNIX APIs. "2222" is a random string the guy pulled out of his ass. there is no sane error convention in which a random string is returned as an error. Why not "oh shit" or "SYNTAX ERROR"? Is the user supposed to guess, or must he read the code to find all possible error return strings (I didn't happen to see any comments). NULL, or "", or whatever the favored VB equivalent is, would have been the right thing to return.
Admin
We all know the proper way to return an error is to return the exception.
nonDev
Admin
How does one get a hexidecimal number outside the range of 0-F anyway?
The quantum bit -1 doesn't seem to have a pair. There's 0 and 1 but only -1. What's it's opposite? -0?
Admin
<FONT face="Courier New" size=2>ERROR: accumulator flooded.
ERROR: distracted by 0xCAFEBABE.
ERROR: i am error.
ERROR: died in the dungeons of doom, level 8.
ERROR: read/write tape jammed.</FONT>
Admin
This actually makes some bit of sense, if he never learned built-in functions.
In some pen-and-paper competitions, you were given problems in hex, and such, and different conversions. Most proper methods of solution involved drawing a quick look-up chart.
Admin
How about J.Lo Endian and Heroin Chic Endian?
Admin
Q: How does hex digit B convert to *a* decimal digit?
A: Incorrectly.
Admin
A number's a number.
More and more, I see Java code (I know the wtf is not java but I feel it's the same issue) where the programmer knows the String class and treats everything as a String (ever saw the "this|should|be|an|object|but|is|a|string" ? .... wtf!).
PS: if the language is VB, doesn't it have libraries that handle string representation for number (things like printf's '%x' or '%o') ?
Admin
IEEE something (the floating point specs) specify a positive and negative 0, for instance, multiplying -5 by 0 is -0. In practice no one cares.
Indeed, in sane hands the Format() function is quite powerful.
Might as well just not return anything and get back garbage or an exception, because you know they aren't checking. In fact, the exception on assignment might be why it was done. God, someone teach this guy about ord().
Admin
I believe in VB6 that you can do the following:
print CInt("&H" & strHexNumber)
Obviously that only works to 32k, otherwise you need a long. (Could also be &h, not sure, I like the 0x notation better)
Drak
Admin
I think the preferred form is "native bytian".
Admin
This has already been posted. Try the seach tool.
Admin
But those are only the Back Endians, what about the Front Endians?<font size="-1">
</font>
Admin
Front Endians operate in a three-pipe output structure that allows 8 bits per pipe. In many preprocessing cases, there is an extra pipe for another 8 bits.
The three pipes command a matrix of light sources, across which three distinct radiation frequencies are approximately evenly spread. Each dot in the matrix emits a level of light in accordance with the binary number represented by the pipeline connected to it.
It's called 24-bit colour on a CRT monitor.
Admin
Brillant.[:P]
Admin
Oooo I like I like!!!! Im gonna start using that one ... reminds me of the alternative try/catch/finally standard I read somewhere
Try
Doh!
Woohoo!
he he :D
Admin
Haha, you could use varying error phrases to indicate how serious the error is. It could vary from "Aw Darn" to "Well Crap" to "...We're boned."
Hmm...I think once I ever actually program something with exceptions Im definitely gonna have to throw in a wereBonedException class.
Admin
Maybe I was sleeping through my CS lectures, but how would -1 be represented differently in big or little endian format?
Admin
Big endian: FF FF ff ff
Little endian: ff ff FF FF
It's all in the intonation.
Admin
eFFF
Fehhhh
?