• Isaac (unregistered)

    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!

  • (cs)

    You gotta love hex2dec("11") returning -1.  Option Explicit wouldn't hurth either.

  • (cs)

    What?  no dec2hex() or bin2hex()?

  • (cs)

    And I always tought that computers numbers were binary. 

  • (cs)

    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.

  • (cs) in reply to rogthefrog
    rogthefrog:
    I guess -1-1-1-1 wouldn't work.


    -4?
  • David (unregistered) in reply to Ross Day

    Ross Day:
    rogthefrog:
    I guess -1-1-1-1 wouldn't work.


    -4?

    Brillant!

     

    Sorry...someone had to say it...

  • (cs) in reply to Ross Day

    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.

  • (cs) in reply to David
    Anonymous:

    Ross Day:
    rogthefrog:
    I guess -1-1-1-1 wouldn't work.


    -4?

    <font size="3">Brillant!</font>

     

    Sorry...someone had to say it...


    That one will live on for quite a while.  Thanks Paula!
  • (cs)

    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.

  • joe_bruin (unregistered)

    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.

  • (cs)

    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!

  • (cs)

    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.

  • dave (unregistered)

    luckily my life exists with the bounds of [0,15]

  • (cs) in reply to Jake Vinson
    Jake Vinson:
    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.


    No doubt that was an instant classic.
  • John (unregistered) in reply to JohnO

    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)

    sub some_larger_routine {
       my $input = shift(@_);
       my $val = 0;
    
       ($input =~ /^[A-F0-9]+$/)
          || (do something error-like);
    
       while (length($input)) {
          $val = $val * 16;
          $val += hex2dec(substr($input, 0, 1, ""));
          }
       return ($val);
       }
    

    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.

  • John (unregistered) in reply to John

    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.

  • (cs) in reply to joe_bruin

    Anonymous:
    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.

    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.

  • (cs) in reply to Jake Vinson

    Jake Vinson:
    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.

    This has already been posted.  Try the seach tool.

  • (cs)
    Alex Papadimoulis:

        Case Else
          hex2bin = "2222"
        Case Else
          hex2dec = -1

    <FONT face="Courier New" size=2>WRONG, WRONG, WRONG!  didn't he read the spec?  these functions are supposed to return "Z"!</FONT>

  • (cs) in reply to dubwai
    dubwai:

    Jake Vinson:
    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.

    This has already been posted.  Try the seach tool.



    Now *that* is brilliant!

    -ds
  • (cs) in reply to joe_bruin
    Anonymous:
    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.

    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.

  • (cs) in reply to DisturbedSaint
    DisturbedSaint:
    dubwai:

    Jake Vinson:
    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.

    This has already been posted.  Try the seach tool.



    Now *that* is brilliant!

    -ds

    Especially the unorthodox spelling of 'search'.

  • George of the Jungle (unregistered) in reply to joe_bruin

    Anonymous:
    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.

    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

  • (cs) in reply to George of the Jungle

    Anonymous:
    I don't even want to go into Big vs Little Endian.

    The world is full of enough discord without this kind of bigotry.  Please, try to keep it professional.

  • marijne (unregistered)

    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.

  • (cs) in reply to marijne

    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

  • (cs) in reply to George of the Jungle

    Anonymous:
    I don't even want to go into Big vs Little Endian.

    Those are called "heavy endian" and "vertically challenged endian" these days.

  • (cs) in reply to John
    Anonymous:
    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".


    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

  • (cs)

    De Ja Vu?

  • joe_bruin (unregistered) in reply to dubwai
    dubwai:

    Anonymous:
    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.

    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.



    -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.
  • nonDev (unregistered)

    We all know the proper way to return an error is to return the exception.

    nonDev

  • tim (unregistered)

    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?

  • (cs) in reply to joe_bruin

    Anonymous:

    Why not "oh shit" or "SYNTAX ERROR"?

    <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>

     

  • Andrei (unregistered)

    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.

  • (cs) in reply to dubwai
    dubwai:

    Anonymous:
    I don't even want to go into Big vs Little Endian.

    The world is full of enough discord without this kind of bigotry.  Please, try to keep it professional.

    How about J.Lo Endian and Heroin Chic Endian?

  • Golly (unregistered) in reply to Gene Wirchenko
    Gene Wirchenko:


    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



    Q: How does hex digit B convert to *a* decimal digit?
    A: Incorrectly.
  • ac (unregistered) in reply to Bustaz Kool

    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') ?

  • (cs) in reply to tim
    Anonymous:
    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?

    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.

    Anonymous:
    PS: if the language is VB, doesn't it have libraries that handle string representation for number (things like printf's '%x' or '%o') ?

    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().
  • (cs) in reply to foxyshadis

    foxyshadis:
    Anonymous:
    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?

    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.

    Anonymous:
    PS: if the language is VB, doesn't it have libraries that handle string representation for number (things like printf's '%x' or '%o') ?

    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().

    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

  • Kayaman (unregistered) in reply to dubwai
    dubwai:

    Anonymous:
    I don't even want to go into Big vs Little Endian.

    The world is full of enough discord without this kind of bigotry.  Please, try to keep it professional.

    I think the preferred form is "native bytian".

  • (cs) in reply to John
    Anonymous:
    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.

    This has already been posted. Try the seach tool.

  • Fabian (unregistered) in reply to Bustaz Kool
    Bustaz Kool:
    dubwai:

    Anonymous:
    I don't even want to go into Big vs Little Endian.

    The world is full of enough discord without this kind of bigotry.  Please, try to keep it professional.

    How about J.Lo Endian and Heroin Chic Endian?



    But those are only the Back Endians, what about the Front Endians?<font size="-1">
    </font>
  • (cs) in reply to Fabian
    Anonymous:
    Bustaz Kool:
    dubwai:

    Anonymous:
    I don't even want to go into Big vs Little Endian.

    The world is full of enough discord without this kind of bigotry.  Please, try to keep it professional.

    How about J.Lo Endian and Heroin Chic Endian?



    But those are only the Back Endians, what about the Front Endians?<font size="-1">
    </font>


    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.
  • Welcome To The Machine (unregistered) in reply to NSCoder

    NSCoder:
    Anonymous:
    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.
    This has already been posted. Try the seach tool.

    Brillant.[:P]

  • Toby (UK) (unregistered) in reply to Welcome To The Machine

    Why not "oh shit"


    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
  • David (unregistered) in reply to Toby (UK)

    Anonymous:
    > Why not "oh shit"

    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

     

    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. 

  • (cs) in reply to George of the Jungle
    Anonymous:

    Anonymous:
    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.

    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


    Maybe I was sleeping through my CS lectures, but how would -1 be represented differently in big or little endian format?
  • (cs) in reply to Caffeine

    Caffeine:
    Maybe I was sleeping through my CS lectures, but how would -1 be represented differently in big or little endian format?

    Big endian: FF FF ff ff

    Little endian: ff ff FF FF

    It's all in the intonation.

  • (cs) in reply to Maurits

    eFFF

    Fehhhh

    ?

Leave a comment on “Quantum Computering”

Log In or post as a guest

Replying to comment #:

« Return to Article