• genitus (unregistered)

    OMG! HAHAHA

    he didn't add 0x so his "bit pattern" isn't what he thinks it is. This is a good WTF, just made my day a little better.

  • Vlad (unregistered)

    While this looks really funny, I have to enlighten you a little bit. The logic here is not boolean. And it's okay; not all logics in this world are boolean.

  • pecus (unregistered)

    I bet he was going to use bit shifts, but for some reason they didn't seem to work right. So instead of solving that problem he resorted to "this" method....

  • (cs) in reply to zip
    zip:
    Pyro:
    There are exactly 10 types of people in the world: those who understand binary and those who don't :)
    There are 2 types of commenters, those that are able to create original humor and those that can only parrot things that were funny five years ago.
    My favourite version: There are 11 types of people in the world - those who understand binary, those who don't, and those who are sick and tired of hearing this old joke.
  • dmh2000 (unregistered)

    If the code REALLY looks like that, there's another WTF hidden: It literally is 1111111 (decimal), not binary 1111111 aka 127

    and the first constant with a leading zero is octal, not decimal or binary.

    0001000 = 512 decimal

  • SMB (unregistered) in reply to dmh2000
    dmh2000:
    >If the code REALLY looks like that, there's another WTF hidden: It literally is 1111111 (decimal), not binary 1111111 aka 127

    and the first constant with a leading zero is octal, not decimal or binary.

    0001000 = 512 decimal

    ...which doesn't actually matter at all, because of the implementation. The only thing that matters is that the numbers are unique.

    I would guess that if he used the numbers 0, 1, 2, 3, 4, etc, this wouldn't look unlike implementations that we have seen a thousand times before (even if non-elegant)

  • IV (unregistered)

    So he knew the idea of bitmasking (although not the implementation), but he didn't know about enumerated types? Wow.

    Captcha: abico

  • Obama Crazy Ass Binary Bit Flipper (Yes You Can!) (unregistered) in reply to this webcomic is a wtf
    this webcomic is a wtf:
    Michael:
    If the code REALLY looks like that, there's another WTF hidden: It literally is 1111111 (decimal), not binary 1111111 aka 127.

    This is actually very nice, we can then change the value to a string, then test for the condition with a simple mid(str(integerflagholder),positiontotest,1). You can't do neat stuff like that with some crazy ass binary bit flipper.

    // positiontotest counts from the right, starting at 0 if((integerflagholder & (1 << positiontotest)) == 0) { // flag not set } else { // flag set }

  • Mike (unregistered)

    Sorry, but has ANYBODY here ever heard of bitfields?

    struct { unsigned email:1; unsigned name:1; unsigned telephone:1; } entry;

    You can then access them like normal chars/short/longs etc. and the compiler handles the bit-wise operations for you. It doesn't get any simpler.

    Everybody who posted stupid comments like the WTF was actually a good idea should resign immediately and look for another job in another field, possibly pizza delivery....

    captcha: secundum

  • mastmaker (unregistered) in reply to Harry
    Harry:
    Pyro:
    There are exactly 10 types of people in the world: those who understand binary and those who don't :)

    There are exactly three types of people in the world. Those that understand true and false and those that don't.

    You missed the third type. I presume that would be those whose 'files are not found'?

  • WorldsOldestProgrammer (unregistered)

    This is one of those WTFs in which the comments are funnier and more WTFy than the original WTF.

    Thanks for the laughs, guys and gals.

  • kthxbai (unregistered)
    Pyro:
    There are exactly 10 types of people in the world: those who understand binary and those who don't :)
    There are 11 types of people, those who can count in Binary and those who can't.
  • Moo cows go moo (unregistered) in reply to Anonymouse
    Anonymouse:
    Since C doesn't usually (outside of certain embedded compilers) support raw binary numbers, most people use octal or hex for constants. Then you get a nice string of 0x0001, 0x0002, 0x0004, 0x0008, 0x0010 etc.
    #define BIT(x) (1 << (x)) #define FLAG_FOO BIT(0) #define FLAG_BAR BIT(1) #define FLAG_BAZ (BIT(2) | BIT(3)) etc.
  • (cs) in reply to gabba
    gabba:
    That first one is actually octal, right? It is in C/C++, anyway.

    No problem, 512 doesn't repeat :)

  • (cs) in reply to this webcomic is a wtf
    this webcomic is a wtf:
    Michael:
    If the code REALLY looks like that, there's another WTF hidden: It literally is 1111111 (decimal), not binary 1111111 aka 127.

    This is actually very nice, we can then change the value to a string, then test for the condition with a simple mid(str(integerflagholder),positiontotest,1). You can't do neat stuff like that with some crazy ass binary bit flipper.

    mid(BigInteger(matchPattern).toString(2),positiontest,1);

    Never say something can't be done.

  • GF (unregistered) in reply to Pyro
    Pyro:
    There are exactly 10 types of people in the world: those who understand binary and those who don't :)
    There are exactly 1 types of people: those who understand boolean logic with binaries, and those who don't.
  • (cs) in reply to operagost
    operagost:
    tgies:
    cthulhu:
    There's nothing essentially wrong with doing it like this, in fact in some situations it is to be prefered.

    You get finer grained control over the business logic if you can handle specific combinations seperately. You can, for example, scroll down to the elseif block that handles the DOB-email-name combination and make it a Special Case with special behavior. It makes it a lot easier to refactor.

    That's not so easy if you just obfuscate it all as a load of bits and masks which by definition have no meta-data attached.

    look how dumb you are

    you should all video in your bitwise operations
    No can do -- all I've got is bits all over the place and a wooden table.

    Would a still photo do? It's a really nice, fine-grain, wooden table.

    Not so sure that this code has anything to do with bitwise operations, though -- just plain, unthinking, lunacy. On the plus side, it's quite easy to refactor.

  • (cs) in reply to mack
    mack:
    anyone who doesn't think that this code is a piece of crap should be slapped across the face with a keyboard. I suppose the author of this code, as well as this comment, have never heard of something called an enumeration.

    If you are setting your program up to have multiple special cases then you are setting your program up wrong.

    I'm beginning to think that the consensus that "the comments are funnier than the WTF" -- which is difficult, in this case, but obviously not impossible -- is correct. Can we have a special, colour-coded, category for "silliest post?" I'd probably win at least one time out of ten, but, hey, I'm competitive. I suggest pink, as in slip.

    Yes, anybody who doubts the craptastic quality of this code should be slapped across the face with a wet keyboard. But not for either of the spurious reasons that mack advocates.

  • dataangel (unregistered) in reply to cthulhu

    Another way of specializing logic for different cases is polymorphism and virtual functions :P

  • Paradoxical Combinator (unregistered) in reply to this webcomic is a wtf

    You're kidding, right?

    /sometimes I can't tell...

  • Madman1969 (unregistered) in reply to cthulhu

    Please tell me your joking

  • Tom JP (unregistered)

    I call it C tic-tac-toe.

  • Tom JP (unregistered) in reply to Madman1969

    OK, my joking.

  • James (unregistered)

    Nobody's made the joke in a while, so I'll take responsibility.

    [image]
  • (cs) in reply to KludgeQueen
    KludgeQueen:
    Aside from the fact that he's using decimal numbers instead of bitstrings, isn't THIS TRWTF:

    " You have only a single integer to represent them. "

    Is he writing for the VIC-20 or something?

    The only thing I can think of is that it's for a DB column, and since adding a new column to the schema may involve secret rituals to the fasci^H^H^H^H^HDBAs lasting many weeks, you would prefer the easier option of simply gouging your eyes out.

  • (cs)

    Even WITH the retarded usage of decimals, he could have found "bitwise" operators if he'd thought about basic arithmetic. Instead of FLAG_1|FLAG_B, just FLAG_1+FLAG_B....

  • atrigent (unregistered) in reply to this webcomic is a wtf
    this webcomic is a wtf:
    Michael:
    If the code REALLY looks like that, there's another WTF hidden: It literally is 1111111 (decimal), not binary 1111111 aka 127.

    This is actually very nice, we can then change the value to a string, then test for the condition with a simple mid(str(integerflagholder),positiontotest,1). You can't do neat stuff like that with some crazy ass binary bit flipper.

    Umm... Have you ever done anything with bitwise operators in any C-derived language? Ever heard of the & operator? And how is being able to test a bit in your bit array simply "neat"? Isn't it one of the most important parts of a bit array implementation?

    In C/C++, you'd do something like this:

    #define FLAG_BIT 5 #define FLAG_MASK (1<<FLAG_BIT)

    /* to set: */ flags |= FLAG_MASK;

    /* to test: */

    if(flags & FLAG_MASK) { /* stuff */ }

    Simple as that.

  • Robin Goodfellow (unregistered) in reply to cthulhu
    cthulhu:
    There's nothing essentially wrong with doing it like this, in fact in some situations it is to be prefered.

    You get finer grained control over the business logic if you can handle specific combinations seperately. You can, for example, scroll down to the elseif block that handles the DOB-email-name combination and make it a Special Case with special behavior. It makes it a lot easier to refactor.

    That's not so easy if you just obfuscate it all as a load of bits and masks which by definition have no meta-data attached.

    There's so many things wrong with this bit of code it's hard to keep track. Firstly, he's not actually using a bit-field, because he screwed up the assignments and is instead using octal / decimal values. He's basically just using a huge enum. Secondly, if you need to special case certain combinations, this is not the way to do it.

  • Ektich (unregistered)

    This is actually hurts :( I mean just looking at it...

  • Where's The Flava (unregistered) in reply to cthulhu
    cthulhu:
    There's nothing essentially wrong with doing it like this, in fact in some situations it is to be prefered.

    ... It makes it a lot easier to refactor.

    That's not so easy if you just obfuscate it all as a load of bits and masks which by definition have no meta-data attached.

    hahahahahahahahahahahahahahahahahahahahahahahaahahahahahahahahahahahahahahahahahahah... (breathes) hahahahahahahahahahahahahahahahahahahahahahahaha did you hahahahahahahahahahahah WRITE hahah this code? hahahahahaha (breathes)

  • Where's The Flava (unregistered) in reply to sweavo
    sweavo:
    Pyro:
    There are exactly 10 types of people in the world: those who understand binary and those who don't :)

    And those who know about ternary

    and the other 7 who don't know about either but work in denary with varying levels of understanding.

    which means 70% of people minimum don't give a monkeys about computers. Is that a good thing? I don't care, I'm a contractor.

  • fatass (unregistered) in reply to tgies
    tgies:
    cthulhu:
    There's nothing essentially wrong with doing it like this, in fact in some situations it is to be prefered.

    You get finer grained control over the business logic if you can handle specific combinations seperately. You can, for example, scroll down to the elseif block that handles the DOB-email-name combination and make it a Special Case with special behavior. It makes it a lot easier to refactor.

    That's not so easy if you just obfuscate it all as a load of bits and masks which by definition have no meta-data attached.

    look how dumb you are

    I love how you didn't obfuscate your reply with those silly bits and masks..

  • Edward Royce (unregistered) in reply to savar
    savar:
    sweavo:
    Pyro:
    There are exactly 10 types of people in the world: those who understand binary and those who don't :)

    And those who know about ternary

    And those who have social anxiety disorder.

    So really there are 4 (decimal) or 100 (binary) kinds of people in the world.

    Actually there are 5 types of people in the world. The 5th type are the people who enjoy eating kimchee.

  • Blaufish (unregistered)

    My eyes hurt!

  • Mr B (unregistered) in reply to dataangel
    dataangel:
    Another way of specializing logic for different cases is polymorphism and virtual functions :P

    Damn! I read that and the words "Strategy Pattern" just popped right into my head. Sealed with a loving KISS.

  • (cs)

    Too many bits...

    Hint: MIPS

  • nikolago (unregistered)

    Awwwwwwwwwww. So many ultra-high-sensitive feelings broken here. :(

    I red some comments first, and then the actual WTF. The actual topic was no match...

  • (cs) in reply to Corona688
    Corona688:
    Even WITH the retarded usage of decimals, he could have found "bitwise" operators if he'd thought about basic arithmetic. Instead of FLAG_1|FLAG_B, just FLAG_1+FLAG_B....
    Hello, overflow.

    Which is quite appropriate for this code.

  • Kyle X (unregistered) in reply to cthulhu

    I smell an old school programmer here.

  • (cs) in reply to this webcomic is a wtf
    this webcomic is a wtf:
    This is actually very nice, we can then change the value to a string, then test for the condition with a simple mid(str(integerflagholder),positiontotest,1). You can't do neat stuff like that with some crazy ass binary bit flipper.

    How's that 'neater' than if(integerflagholder&(1<<positiontotest))?

  • Gur (unregistered) in reply to this webcomic is a wtf
    this webcomic is a wtf:
    This is actually very nice, we can then change the value to a string, then test for the condition with a simple mid(str(integerflagholder),positiontotest,1). You can't do neat stuff like that with some crazy ass binary bit flipper.

    Sure you can. Use bit operations, they're easy and mad fast. The prefered way would be something like:

    #define LNAME 1 #define FNAME 2 #define DOB 4 ..etc

    int matchPattern = 0; if (hasLastName) matchPattern |= LNAME; if (hasFirstName) matchPattern |= FNAME; ..etc

    if (matchPattern & FNAME) // match first name

    And to replace your example:

    mid(str(integerflagholder),positiontotest,1); // your version bitflagholder & (1 << positiontotest); // though, position to test starts from the other side now, but you get the point.

  • Gur (unregistered)

    Yes, I will now proceed by writing "click all comments before replying" 1000 times. Sorry for noting it wasn't answered and beaten to death yet. Though, the real wtf is still in the first few comments though.

  • Christian Vogel (unregistered)

    While I really loathe it, that kind of providing several booleans is actually quite common. The current incarnation of "Root" (A data analysis behemoth^Wframework) for example uses this:

    http://root.cern.ch/root/html/TStyle.html#TStyle:SetOptStat

    SetOptStat(Int_t mode): The type of information printed in the histogram statistics box can be selected via the parameter mode. The parameter mode can be = ksiourmen (default = 000001111) k = 1; kurtosis printed k = 2; kurtosis and kurtosis error printed s = 1; skewness printed s = 2; skewness and skewness error printed i = 1; integral of bins printed o = 1; number of overflows printed u = 1; number of underflows printed r = 1; rms printed r = 2; rms and rms error printed m = 1; mean value printed m = 2; mean and mean error values printed e = 1; number of entries printed n = 1; name of histogram is printed
  • (cs) in reply to Nitehawk
    Nitehawk:
    Well if they are going to be highlighting the troll posts, I think its time to quit reading this site.

    I hope to god they highlight that one.

  • Indima (unregistered)

    So what?? This is perfectly good coding. This site is getting soo boring nowadays. :-|

  • (cs) in reply to Christian Vogel
    Christian Vogel:
    While I really loathe it, that kind of providing several booleans is actually quite common. The current incarnation of "Root" (A data analysis behemoth^Wframework) for example uses this:

    http://root.cern.ch/root/html/TStyle.html#TStyle:SetOptStat

    SetOptStat(Int_t mode): The type of information printed in the histogram statistics box can be selected via the parameter mode. The parameter mode can be = ksiourmen (default = 000001111) k = 1; kurtosis printed k = 2; kurtosis and kurtosis error printed s = 1; skewness printed s = 2; skewness and skewness error printed i = 1; integral of bins printed o = 1; number of overflows printed u = 1; number of underflows printed r = 1; rms printed r = 2; rms and rms error printed m = 1; mean value printed m = 2; mean and mean error values printed e = 1; number of entries printed n = 1; name of histogram is printed
    On the off-chance that zeros are permitted, as per the spec of the default, would you kindly explain how any of this is boolean?

    Ooh, ooh, I know.

    FILE_NOT_FOUND.

  • (cs) in reply to cthulhu

    You fail.

  • Anon Coward (unregistered) in reply to mastmaker

    No, the third are SQL DBA's who know that the third value is NULL.

    Except NULL isn't a value, of course..

  • NiceWTF (unregistered) in reply to Michael
    Michael:
    If the code REALLY looks like that, there's another WTF hidden: It literally is 1111111 (decimal), not binary 1111111 aka 127.

    This must be a new paradigm, I propose we call it "Reverse Binary Coded Decimals"

  • wtf (unregistered) in reply to Harry
    Harry:
    Pyro:
    There are exactly 10 types of people in the world: those who understand binary and those who don't :)
    There are exactly three types of people in the world. Those that understand true and false and those that don't.
    There are exactly three types of people in the world. Those that can count and those that can't.

Leave a comment on “Boolean Integers”

Log In or post as a guest

Replying to comment #:

« Return to Article