A Bit Misguided

  • ParkinT 2012-12-04 06:52
    WOW.
    That's not "reinventing the wheel".
    That is Reinventing Fire!!!
  • daef 2012-12-04 08:02
    TRWTF is the endianess... LSB should be on [0] in my opinion...
  • daef 2012-12-04 08:07
    yeah - every coder should know that there is an OR statement for things like this...:


    var rules = [];

    if ( inputInt == 1
    || inputInt == 3
    || inputInt == 5
    || inputInt == 7
    || /* snip */ )
    rules[0] = 1;
    else
    rules[0] = 0;

    if ( inputInt == 2
    || inputInt == 3
    || inputInt == 6
    || inputInt == 7
    || /* snip */ )
    rules[1] = 1;
    else
    rules[1] = 0;

    if ( inputInt == 4
    || inputInt == 5
    || inputInt == 6
    || inputInt == 7
    || /* snip */ )
    rules[2] = 1;
    else
    rules[2] = 0;


    </sarcasm>
  • ColdHeart 2012-12-04 08:07
    really people... make it a function and stop copying code everywhere!
  • Hmmmm 2012-12-04 08:07
    Cue large number of horrendously bad attempts at writing this in [one line/a language of choice/a highly obfuscated manner] that should make any competent programmer weep for the future of humanity...
  • TheSHEEEP 2012-12-04 08:12
    What... uh... oh god... *strange noise*

    I don't see the WTF here.

    I only see a vast green pasture with some happy animals on it. It seems very peaceful and looking at it comforts me and restores my inner balance.
  • snoofle 2012-12-04 08:15
    He used integers. I suppose it could be worse; he might have used booleans, and we all know how much trouble people like this have with the complexity of booleans!
  • Ron 2012-12-04 08:15
    Paid (or otherwise incentivized) by lines of code, I'll bet. This is why you have to reward what you want, not unrelated measures you think might get you closer to what you want.
  • Smug Unix User 2012-12-04 08:18
    Make sure to subtly change the function in places and have code dependencies on it working slightly differently.
  • Larry 2012-12-04 08:19
    for $R (0 .. 7) { $Rules[$R] = ( inputInt == int(inputInt/2)*2 ? 0 : ( inputInt == int(inputInt/4)*4 ? 0 : (

    Oh, hell. I give up. If it works, don't fix it.
  • Reggie 2012-12-04 08:21
    You have a problem. You think "I know, I'll use bits." Now you have 10 problems.
  • Jaloopa 2012-12-04 08:22
    Ron:
    Paid (or otherwise incentivized) by lines of code, I'll bet. This is why you have to reward what you want, not unrelated measures you think might get you closer to what you want.


    Ok, seriously - has anybody ever actually known a job where people are paid by the line? It comes up every time a verbose piece of code is featured but I find it hard to believe that even the pointiest haired of bosses would think it's a good idea
  • Honnza 2012-12-04 08:26
    Here's an implementation in Javascript:


    Number.prototype.to8bitLEArray = function(){
    return ("00000000"+(this|0).toString(2)).split("").slice(-8);
    }
  • Andrew 2012-12-04 08:27
    I would have said ArrayIndexOutOfBoundsException, but the "var rules = [];" suggests that this is Javascript.
  • Uh... 2012-12-04 08:34
    Like this?

    rules = [int(x) for x in "{:08b}".format(inputInt)]
  • Frz 2012-12-04 08:34
    Honnza:
    Here's an implementation in Javascript:


    Number.prototype.to8bitLEArray = function(){
    return ("00000000"+(this|0).toString(2)).split("").slice(-8);
    }

    Nice.. but extending builtin "Types" brings more problems than it solves.
  • ubersoldat 2012-12-04 08:36
    Reggie:
    You have a problem. You think "I know, I'll use bits." Now you have 10 problems.


    Don't mind if I use this extensively with other quotes.
  • snoofle 2012-12-04 08:39
    Jaloopa:
    Ron:
    Paid (or otherwise incentivized) by lines of code, I'll bet. This is why you have to reward what you want, not unrelated measures you think might get you closer to what you want.


    Ok, seriously - has anybody ever actually known a job where people are paid by the line? It comes up every time a verbose piece of code is featured but I find it hard to believe that even the pointiest haired of bosses would think it's a good idea
    Not by the line, but I have worked at a place where they tried paying incentives ($25) per bug fix - the idea being that folks would rip through the bug list and make the app perfect.

    What they forgot to do was put in a charge of $50 for every new bug introduced!
  • John 2012-12-04 08:48
    So how did they deal with porting this code to a 16-bit machine?

    The pending 64-bit upgrade must be truly impressive ...
  • SeySayux 2012-12-04 08:57

    template<class CharT>
    bool boolify(CharT c) {
    return c == '1';
    }

    template<class OutputIterator, std::size_t N>
    void to_bit_sequence(std::bitset<N> bits, OutputIterator out) {
    std::string str = bits.to_string();

    std::transform(str.begin(), str.end(), out, boolify<char>);
    }

    int main(int argc, char** argv) {
    if(argc != 2) return 1;

    std::vector<bool> out;

    to_bit_sequence(std::bitset<8>(argv[1]), out.begin());
    std::transform(out.begin(), out.end(),
    std::ostream_iterator(std::cout, ", "));
    }
  • Nonody 2012-12-04 08:59
    In fact you'll have 99 problems, but the bits aint one


  • History Teacher 2012-12-04 09:00
    Ouch. Why does this suddenly give me a headache? I mean, it's just regular WTF quality code, nothing to see here really... Strange.

    As a mental exercise, think, when did things go wrong in the creation of this code? What was the exact event, where reality and sanity parted ways in this case?
  • urza9814 2012-12-04 09:11
    History Teacher:
    As a mental exercise, think, when did things go wrong in the creation of this code? What was the exact event, where reality and sanity parted ways in this case?


    ...when the author of this WTF was hired?
  • @Deprecated 2012-12-04 09:16
    This is crying out for an enterprise-y database solution.
    That way it can be easily extended to 64 bits!
  • LoremIpsumDolorSitAmet 2012-12-04 09:16
    Now back that function up with 256 individual JSunit test cases and you're golden. Oh, but wait, it isn't a function. Guess you'll have copy-paste the tests too for each place in which this code is used. On the plus side, your code coverage will look amazing.

    Each if-block is about 294 bytes. 256 blocks makes 75KB uncompressed. I'm sure the users of that website will appreciate how fast it loads!
  • AGray 2012-12-04 09:18
    I'm a C# guy...why couldn't they do something along the lines of...


    [Flags]
    public enum FlagSystem
    {
    A = 0,
    B = 1,
    C = 2,
    // ...
    N = N ^ 2
    }

    short mask = FlagSystem.A | FlagSystem.B | FlagSystem.N;


    It's not that tough of a concept, though I haven't used flags in months and have probably botched the above code big time. :(
  • flyboyfred 2012-12-04 09:18
    What's beautiful about this code is how well it scales. Imagine how easy it would be to extend it to 16 or 32 bits!
  • Sweet Brown 2012-12-04 09:26
    Ain't nobody got time for that.

    Where's the easy reader version? :P
  • Peter 2012-12-04 09:27
    Ok, seriously - has anybody ever actually known a job where people are paid by the line?


    Those
    jobs
    are
    hard
    to
    come
    by
    and
    their
    availability
    is
    a
    closely
    guarded
    secret
    by
    those
    who
    are
    making
    a
    fortune
    from
    them
  • dgvid 2012-12-04 09:29
    Jaloopa:
    Ron:
    Paid (or otherwise incentivized) by lines of code, I'll bet. This is why you have to reward what you want, not unrelated measures you think might get you closer to what you want.

    Ok, seriously - has anybody ever actually known a job where people are paid by the line? It comes up every time a verbose piece of code is featured but I find it hard to believe that even the pointiest haired of bosses would think it's a good idea


    A major factor in the rift between IBM and Microsoft over OS/2 was that IBM was pressuring Microsoft to write more lines of code. Bill Gates likened it to paying for a new aircraft design by the pound. Of course, that's still not any individual being paid by the line, but I assume that IBM's coders on OS/2 were being incentivized in some way to write more lines.
  • Antti Nagesh 2012-12-04 09:30
    Reggie:
    You have a problem. You think "I know, I'll use bits." Now you have 10 problems.


    This should be a featured comment!
  • Tronic 2012-12-04 09:31
    as far as code goes, I like the simple but readable version.
    var rules[];
    for( int i = 0; i<8; i++){
    rules[i]=inputInt%(2^i);
    }
  • 3rd Ferguson 2012-12-04 09:37
    flyboyfred:
    What's beautiful about this code is how well it scales. Imagine how easy it would be to extend it to 16 or 32 bits!


    Actually...

    You could extend to 64 bits by pushing 8 rules[] into a rulesSixtyFour[]. Not sure how to populate it, though. Maybe do modulo 2^32, 2^31, 2^30, ..., 2^25 on the input to figure which of the eight rules[] arrays to operate on. Within each array you might do modulo eight more times to figure which bit to set.

    It's still horrible but at least it's actually fewer operations than the original code. For nostalgia and backwards compatibility I guess you could leave the original for setting the last 8 bits.

    Don't get uppity if I'm totally wrong, this morning's cappuccino is only half gone...
  • Rodnas 2012-12-04 09:38
    And now our faculty rules:

    ---snip---
    Rule six:
    There is NO rule six.
    rule seven:
    No Poeftas
  • pencilcase 2012-12-04 09:39
    snoofle:
    Jaloopa:
    Ron:
    Paid (or otherwise incentivized) by lines of code, I'll bet. This is why you have to reward what you want, not unrelated measures you think might get you closer to what you want.


    Ok, seriously - has anybody ever actually known a job where people are paid by the line? It comes up every time a verbose piece of code is featured but I find it hard to believe that even the pointiest haired of bosses would think it's a good idea
    Not by the line, but I have worked at a place where they tried paying incentives ($25) per bug fix - the idea being that folks would rip through the bug list and make the app perfect.

    What they forgot to do was put in a charge of $50 for every new bug introduced!

    I worked at a place (long ago) where they had previously paid guys by the number of COBOL modules they wrote. This obviously led to an outpouring of modules performing e.g. "Return 1" equivalent. Fortunately, it was fairly easy to mop them up and laugh a bit.
  • goom 2012-12-04 09:52
    Tronic:
    as far as code goes, I like the simple but readable version.
    var rules[];
    for( int i = 0; i<8; i++){
    rules=inputInt%(2^i);
    }

    That certainly works but as [i]daef
    pointed out the rules are big-endian while your loop puts them in little-endian order (or do I have it backwards?).

    Assuming that the endianess is required, I would do something like this:
    rules[0] = inputInt & 128;
    
    rules[1] = inputInt & 64;
    rules[2] = inputInt & 32;
    rules[3] = inputInt & 16;
    rules[4] = inputInt & 8;
    rules[5] = inputInt & 4;
    rules[6] = inputInt & 2;
    rules[7] = inputInt & 1;
  • WhiskeyJack 2012-12-04 10:00
    Jaloopa:

    Ok, seriously - has anybody ever actually known a job where people are paid by the line? It comes up every time a verbose piece of code is featured but I find it hard to believe that even the pointiest haired of bosses would think it's a good idea


    In a recent project I worked on, we weren't being paid for lines of code but management was very, very interested in keeping metrics on them. We would frequently have to submit statistics (or they would be calculated from tools we used). How many lines of code did you produce this week? How long did it take your peers to code review? Therefore, how many LOC/minute do they review? How many bugs came out of this section of code? How many LOC/bug? How many LOC in your module? Compared to every other module? etc, etc, etc. It was kind of nuts, but at least it didn't really get in the way of the job itself.

    They were trying to quantify things like, given an average of X lines impacted per bug, and it takes Y hours to fix, therefore how many bugs can a developer fix per day, therefore we can schedule in Z bug fixes per week...
  • noname 2012-12-04 10:03
    Well, that's impressive 2304 lines of code. One cent per line makes it $23.04. If he takes longer than half an hour he wasted his and his employers money.
  • LoremIpsumDolorSitAmet 2012-12-04 10:04
    Antti Nagesh:
    Reggie:
    You have a problem. You think "I know, I'll use bits." Now you have 10 problems.

    This should be a featured comment!

    And now it won't be, you insensitive clod.
  • Techpaul 2012-12-04 10:06
    snoofle:
    He used integers. I suppose it could be worse; he might have used booleans, and we all know how much trouble people like this have with the complexity of booleans!


    Hmm

    Nah it should XML encoded strings of floats to be really sure he captured EVERY possibility including sign, infinity and of course NaN
  • Kanitatlan 2012-12-04 10:18
    But just wait until you see the code to translate the rules back into a value, I have. Its munitions grade bad code and hence health & safety forbids posting it.
  • DCRoss 2012-12-04 10:20
    urza9814:
    History Teacher:
    As a mental exercise, think, when did things go wrong in the creation of this code? What was the exact event, where reality and sanity parted ways in this case?


    ...when the author of this WTF was hired?


    ...straight out of school.

    Perhaps next time they should wait until after graduation.
  • Foo Bar 2012-12-04 10:22
    EVERY possibility including sign, infinity and of course NaN

    You forgot File Not Found.
    Also, Poland.
  • JR 2012-12-04 10:23
    hum higher order bit is with index 7! Wait other way! it's zero.

  • gpsguru 2012-12-04 10:36
    Duh, he should have used a switch statement.
  • Snowrat 2012-12-04 10:37
    rules←inputInt⊤⍨8/2
    rules←2|⌽⌊{⍵÷2}\8/inputInt

    The later one is my favourite so far.
  • David Emery 2012-12-04 10:41
    The interesting thing about the code sample is that any reasonably competent compiler will take at least the assignment code and optimize it. An even better compiler will recognize the whole thing is -static code- and produce a very tight representation.

    Those of you who propose generating this with some functions should recognize that, depending on the expression, the programming language and the quality of the compiler, you'll end up running that code when you didn't have to.
  • d 2012-12-04 10:43
    ParkinT:
    WOW.
    That's not "reinventing the wheel".
    That is Reinventing Fire!!!
    Using kerosene.
  • Nico 2012-12-04 10:45
    I don't get that... Shouldn't it be

    "You have two problems. You think "I know, I'll use bits." Now you have 10 problems."
  • dtech 2012-12-04 10:46
    goom:
    Tronic:
    as far as code goes, I like the simple but readable version.
    var rules[];
    for( int i = 0; i<8; i++){
    rules=inputInt%(2^i);
    }

    That certainly works but as [i]daef
    pointed out the rules are big-endian while your loop puts them in little-endian order (or do I have it backwards?).

    Assuming that the endianess is required, I would do something like this:
    rules[0] = inputInt & 128;
    
    rules[1] = inputInt & 64;
    ...
    rules[7] = inputInt & 1;


    That... or just:

    int size; // E.g. rules.size() or something
    for(int i=0;i<size;i++) {
    rules[i] = inputInt & (1 << (size-i));
    }


    (Parentheses added for clarity, not actually necessary)
  • urza9814 2012-12-04 11:11
    Clearly this programmer does not understand how to use bits like this properly, therefore all they did was create a new problem. So they went from one problem to two...but they're doing it in binary now so they went from one problem to 10.
  • urza9814 2012-12-04 11:13
    Ah crap I screwed up my quotes. Should have been:

    Nico:
    I don't get that... Shouldn't it be

    "You have two problems. You think "I know, I'll use bits." Now you have 10 problems."


    Clearly this programmer does not understand how to use bits like this properly, therefore all they did was create a new problem. So they went from one problem to two...but they're doing it in binary now so they went from one problem to 10.
  • Paul Neumann 2012-12-04 11:19
    dtech:
    That... or just:

    int size; // E.g. rules.size() or something
    for(int i=0;i<size;i++) {
    rules[i] = inputInt & (1 << (size-i));
    }


    (Parentheses added for clarity, not actually necessary)
    CodeAnalyses sees your unnecessary parentheses and throws a compiler error upon gated check in. :( I hate VS/TFS/CodeCop
  • Cbuttius 2012-12-04 11:26
    Jaloopa:


    Ok, seriously - has anybody ever actually known a job where people are paid by the line? It comes up every time a verbose piece of code is featured but I find it hard to believe that even the pointiest haired of bosses would think it's a good idea


    Usually they think code is charged by the line, therefore for me to sit and write code that might not get used, or hasn't been budgeted for is a great expense, compared to me sitting in the office reading and posting on TheDailyWTF.
  • Jack 2012-12-04 11:27
    Reggie:
    You have a problem. You think "I know, I'll use bits." Now you have 10 problems.
    I think you've just captured the thesis of this entire site.

    /comment
    /thread
    /article
    /tdwtf
  • Daniel 2012-12-04 11:27
    And to make his live easier, he wrote a code generator that simply wrote this stuff out... without just using the code generators code in his function.
  • David 2012-12-04 11:28
    Don't you mean 8 problems. Unless you are running this: http://en.wikipedia.org/wiki/Ferranti_Mercury
  • Cbuttius 2012-12-04 11:30
    goom:

    Assuming that the endianess is required, I would do something like this:
    rules[0] = inputInt & 128;
    
    rules[1] = inputInt & 64;
    rules[2] = inputInt & 32;
    rules[3] = inputInt & 16;
    rules[4] = inputInt & 8;
    rules[5] = inputInt & 4;
    rules[6] = inputInt & 2;
    rules[7] = inputInt & 1;

    Close but it won't give you the output in 1 and 0 values.

    You could either use a ternary notation or a bit shift to fix that.
  • the guy with a name 2012-12-04 11:37
    Wow.
    Just waste those 256 bytes and generate them into a static array first. It's still terrible tho'.


    var rules = rulesArray[inputInt];

  • operagost 2012-12-04 11:43
    dgvid:
    Jaloopa:
    Ron:
    Paid (or otherwise incentivized) by lines of code, I'll bet. This is why you have to reward what you want, not unrelated measures you think might get you closer to what you want.

    Ok, seriously - has anybody ever actually known a job where people are paid by the line? It comes up every time a verbose piece of code is featured but I find it hard to believe that even the pointiest haired of bosses would think it's a good idea


    A major factor in the rift between IBM and Microsoft over OS/2 was that IBM was pressuring Microsoft to write more lines of code. Bill Gates likened it to paying for a new aircraft design by the pound. Of course, that's still not any individual being paid by the line, but I assume that IBM's coders on OS/2 were being incentivized in some way to write more lines.

    That's probably true, but it doesn't explain why, ironically, Windows was the far more bloated product. I mean, I knew people who actually managed to run OS/2 on 4 MB machines-- but with Win 95, that was an absolute horror.
  • Ralph 2012-12-04 11:47
    operagost:
    on 4 MB machines-- but with Win 95, that was an absolute horror.
    Surely that was a typo, and you mean 4 GB, right?

    (My first computer had 8 KB. And we liked it.)
  • Long Version Please 2012-12-04 11:51
    Can some one please post this code with the snipped lines ? Too lazy to do it myself, offcourse.

    FYI, I am being paid by lines of code, and am planning to copy paste this code. It will be my December bonus!
  • Matthew 2012-12-04 12:01
    I especially like the ski jumping snowman in the second line.
  • ¯\(°_o)/¯ I DUNNO LOL 2012-12-04 12:11
    This is so awesome! They should add it to PHP!
    input_int_to_rules(input_int) - returns rules as an array
  • chubertdev 2012-12-04 12:12
    I guess that he wasn't "bit-wise"
  • some guy 2012-12-04 12:22
    Unless that was an intentional comical spelling, I think you'll find the word is poofters.
  • Santa 2012-12-04 12:29
    whats most interesting is that someone actually had the knowledge to do binary conversion yet they did not had the sence to do it properly.
  • Sheldon Cooper 2012-12-04 13:03
    noname:
    Well, that's impressive 2304 lines of code. One cent per line makes it $23.04. If he takes longer than half an hour he wasted his and his employers money.
    (a) If you're paid by the line, you should demand a little more than 1 cent per line (unless you're Nagesh). (b) He did waste his employer's money, no matter what.
  • RFoxmich 2012-12-04 13:13
    TRWTF is it only handles a byte. Keep on going for 4,294,967,040 >more< cases for my 32 bit machine...and I don't even want to think about this for my 64 bit systems.

    Now the programmer who's savvy with bits would just write a program to write that code for an arbitrary number of bits right :-D

    TheSHEEEP:
    What... uh... oh god... *strange noise*

    I don't see the WTF here.

    I only see a vast green pasture with some happy animals on it. It seems very peaceful and looking at it comforts me and restores my inner balance.
  • Wyrm 2012-12-04 13:33
    Reggie:
    You have a problem. You think "I know, I'll use bits." Now you have 10 problems.

    That's a good one.
    Too bad binary jokes only work when written.
  • Dazed 2012-12-04 13:35
    dgvid:
    Jaloopa:
    Ok, seriously - has anybody ever actually known a job where people are paid by the line? It comes up every time a verbose piece of code is featured but I find it hard to believe that even the pointiest haired of bosses would think it's a good idea


    A major factor in the rift between IBM and Microsoft over OS/2 was that IBM was pressuring Microsoft to write more lines of code. Bill Gates likened it to paying for a new aircraft design by the pound. Of course, that's still not any individual being paid by the line, but I assume that IBM's coders on OS/2 were being incentivized in some way to write more lines.

    I have read that some of IBM's code-quality tools included counts of entity X per 1000 lines of code and compared them to some arbitrary maximum. And the coders would then bulk the code up with silly lines to get it to pass the quality checks.
  • Alex 2012-12-04 13:39
    I'll say it...

    you've got 64 problems and a bit's every one.
  • Yet Another Steve 2012-12-04 13:41
    I've never been *paid* by the line, but a former COBOL shop I worked in (back when the Earth was still cooling) required the programmers (I was 1 of 3) to submit weekly status reports showing how many lines of code we produced per week/day/hour. If we dropped below a certain average, we had to justify where our time went.

    Or
    we
    just
    produced
    more
    lines.
  • Maurits 2012-12-04 14:02
    Wyrm:
    Reggie:
    You have a problem. You think "I know, I'll use bits." Now you have 10 problems.

    That's a good one.
    Too bad binary jokes only work when written.


    Trying to read binary numbers as their decimal equivalent quickly runs into problems as the numbers get big.

    Here's how to count in binary:

    One, ten, eleven, one hundred, one hundred one, one hundred ten, one hundred eleven, one thousand...

    Reading hexadecimal numbers this way runs into the problem that 18 and 1A are homonyms (eighteen vs. "A"-teen). So I suggest reading them by reading the digits (one-eight, one-"A")
  • jay 2012-12-04 14:04
    Jaloopa:
    Ron:
    Paid (or otherwise incentivized) by lines of code, I'll bet. This is why you have to reward what you want, not unrelated measures you think might get you closer to what you want.


    Ok, seriously - has anybody ever actually known a job where people are paid by the line? It comes up every time a verbose piece of code is featured but I find it hard to believe that even the pointiest haired of bosses would think it's a good idea


    I once had a job where management discussed giving bonuses based on lines of code produced. I got my hopes up: I can easily think of dozens of ways to boost line count. Like, don't write "x=x+2", write "x=x+1" twice. Loops? Crazy idea. Make multiple copies of the code. Etc. Sadly, they dropped the idea.

    That said, there are plenty of companies out there that pay by the hour, and that's not a lot different.

    When I worked for the government, one project team was given an award, with a big ceremony and a high muck-a-muck presentating a plaque and all that, for producing the most paperwork. I don't mean that they fooled the higher-ups and all they ever really did was produce paperwork. I mean, the stated reason for them receiving the award, for which they were praised by the high officials, was that they had filled out more forms and produced more documents than any other project team. Oh, by the way, the actual software that they were supposed to produce? They never managed to implement most of the required functionality. They were supposed to support 20,000 users, but their system crashed whenever they got more than 7, and they were never able to get it to run with anything remotely resembling a realistic load. The project was eventually cancelled. But, hey, the filled out all the forms correctly.
  • jay 2012-12-04 14:11
    dtech:
    goom:
    Tronic:
    as far as code goes, I like the simple but readable version.
    var rules[];
    for( int i = 0; i<8; i++){
    rules=inputInt%(2^i);
    }

    That certainly works but as [i]daef
    pointed out the rules are big-endian while your loop puts them in little-endian order (or do I have it backwards?).

    Assuming that the endianess is required, I would do something like this:
    rules[0] = inputInt & 128;
    
    rules[1] = inputInt & 64;
    ...
    rules[7] = inputInt & 1;


    That... or just:

    int size; // E.g. rules.size() or something
    for(int i=0;i<size;i++) {
    rules[i] = inputInt & (1 << (size-i));
    }


    (Parentheses added for clarity, not actually necessary)


    I was thinking of the loop being i=0,j=1;j<255;++i,j*=2, but yeah, same idea.

    The difference between doing it with a 2- or 3-line loop rather than hundreds of lines of a big case statement is not just that the loop is easier to write, but more importantly that it is easier to verify. I can test the loop version with three or four cases and be confidant that it is correct. But with the "unrolled" version, how do I seriously verify that in all that typing or copy-paste editing, at some point I didn't make a mistake? I've seen exactly that in such code. Buried deep down inside somewhere, instead of saying "rule[0]=0; rule[1]=1;" it actually says "rule[0]=0; rule[0]=1;" and never sets rule[1], because someone made a typo.
  • urza9814 2012-12-04 14:12
    Uh, my Windows 98 box had only 64MB. And that was pretty decent at the time.

    I suspect you are talking about hard drive space. He meant primary memory. RAM.

    Of course even then, 4GB hard drive space would have been fairly large. Certainly more than the minimum for Win95, which I recall using on systems with only a gig of disk space. With 4GB I think you could even run XP (assuming you didn't plan on installing much else!)
  • PiisAWheeL 2012-12-04 14:17
    Nonody:
    In fact you'll have 01100011 problems, but the bits aint one
    FTFY.
  • jay 2012-12-04 14:19
    And in real life, the obvious follow on to this is that someone who's an even bigger idiot than the person who wrote the original code will say, Oh, there's a place where the value I pass in is the customer flags, but we just got a change request from the user that customer flag #4 should be treated as zero whenever flags 1, 2, and 3 are 1, 0, and 1 and the customer has account type W, so I'll just add this global that is true when the customer account type is W, and let's see, I think I'll call it "customer_account_type_w" ... no, that's too much to type, let's just call it "cw" ... and then inside case 13 I'll just add "if (cw) rule[4]=0 else rule[4]=1", and, yeah, that should take care of it.

    I have seen this scenario hundreds of times.
  • Vortico 2012-12-04 14:22
    Generalized:

    You have n problems. You think "I know, I'll use bits." Now you have 2^n problems.
  • wiseass 2012-12-04 14:33
    Who said reinventing the wheel was a bad idea? If we would not have reinvented the wheel time and time again in the past, we would still have stone tires on our 'cars', would not be able to go faster than 10 mph, and would break said wheels after somewhere around 20 miles.
  • freealloc 2012-12-04 14:35
    TRWTF is how bad all the solutions are in the comments also are. It's not hard, people. You don't need to overuse STL and definitely shouldn't hardcode the size of the output array.

    The closest was this one:
    rules[i] = inputInt & (1 << (size-i));
    However, that will not set the lowest bit in each array element but bit being checked.


    Replace type with the desired data type.

    void toBitArray(type var, unsigned char* bitArray)
    {
    for( int i = 0; i < sizeof(type)*8; ++i)
    {
    bitArray[i] = (var >> i) & 1;
    }
    }

  • Jazz 2012-12-04 14:35
    Foo Bar:
    EVERY possibility including sign, infinity and of course NaN

    You forgot File Not Found.
    Also, Poland.


    Dammit, I always forget Poland. What with it being all the way over in Europe, and all.
  • Jazz 2012-12-04 14:36
    wiseass:
    Who said reinventing the wheel was a bad idea? If we would not have reinvented the wheel time and time again in the past, we would still have stone tires on our 'cars', would not be able to go faster than 10 mph, and would break said wheels after somewhere around 20 miles.


    And now you have discovered the difference between reinventing and merely iterating.

    (Captcha: erat - I smell erat!)
  • Brian 2012-12-04 15:03
    Unless the person had a reason for doing so, it's not even semantically correct. The bits are in reverse order.

    Captcha: erat = Electronic Rat
  • Bob 2012-12-04 15:06
    LoremIpsumDolorSitAmet:
    Antti Nagesh:
    Reggie:
    You have a problem. You think "I know, I'll use bits." Now you have 10 problems.

    This should be a featured comment!

    And now it won't be, you insensitive clod.

    I had a son who was a featured comment, you insensitive clod. And let me tell you it was no laughing matter.
  • anon 2012-12-04 15:10
    WhiskeyJack:
    Jaloopa:

    Ok, seriously - has anybody ever actually known a job where people are paid by the line? It comes up every time a verbose piece of code is featured but I find it hard to believe that even the pointiest haired of bosses would think it's a good idea


    In a recent project I worked on, we weren't being paid for lines of code but management was very, very interested in keeping metrics on them. We would frequently have to submit statistics (or they would be calculated from tools we used). How many lines of code did you produce this week? How long did it take your peers to code review? Therefore, how many LOC/minute do they review? How many bugs came out of this section of code? How many LOC/bug? How many LOC in your module? Compared to every other module? etc, etc, etc. It was kind of nuts, but at least it didn't really get in the way of the job itself.

    They were trying to quantify things like, given an average of X lines impacted per bug, and it takes Y hours to fix, therefore how many bugs can a developer fix per day, therefore we can schedule in Z bug fixes per week...

    Long ago in the 80s, managers at Apple thought they could measure developer progress with the metric of "lines of code per week." They stopped doing that when the smartest guys in the room had gangbuster progress while simultaneously reporting negative 2000 lines in a week.

    www.folklore.org/StoryView.py?story=Negative_2000_Lines_Of_Code.txt
  • anon 2012-12-04 15:11
    WhiskeyJack:
    Jaloopa:

    Ok, seriously - has anybody ever actually known a job where people are paid by the line? It comes up every time a verbose piece of code is featured but I find it hard to believe that even the pointiest haired of bosses would think it's a good idea


    In a recent project I worked on, we weren't being paid for lines of code but management was very, very interested in keeping metrics on them. We would frequently have to submit statistics (or they would be calculated from tools we used). How many lines of code did you produce this week? How long did it take your peers to code review? Therefore, how many LOC/minute do they review? How many bugs came out of this section of code? How many LOC/bug? How many LOC in your module? Compared to every other module? etc, etc, etc. It was kind of nuts, but at least it didn't really get in the way of the job itself.

    They were trying to quantify things like, given an average of X lines impacted per bug, and it takes Y hours to fix, therefore how many bugs can a developer fix per day, therefore we can schedule in Z bug fixes per week...

    Long ago in the 80s, managers at Apple thought they could measure developer progress with the metric of "lines of code per week." They stopped doing that when the smartest guys in the room had gangbuster progress while simultaneously reporting negative 2000 lines in a week.

    http://www.folklore.org/StoryView.py?story=Negative_2000_Lines_Of_Code.txt
  • Zylon 2012-12-04 15:16
    Vortico:
    Generalized:

    You have n problems. You think "I know, I'll use bits." Now you have 2^n problems.

    Whoooosh.
  • Anonymouse 2012-12-04 15:18
    Ya got masking problems?
    I feel bad for you son.
    I got 1100011 problems
    But a bit ain't one. ;)
  • Tom 2012-12-04 15:19
    Jaloopa:

    Ok, seriously - has anybody ever actually known a job where people are paid by the line? It comes up every time a verbose piece of code is featured but I find it hard to believe that even the pointiest haired of bosses would think it's a good idea


    I did have a job once where productivity - though not directly pay - was measured by lines of code.

    Same job where I was asked to make the internet 100% reliable, when dial-up was the standard (yes, this was years ago). It was like living a Dilbert comic.
  • Jack 27 2012-12-04 15:29
    Tronic:
    as far as code goes, I like the simple but readable version.
    var rules[];
    for( int i = 0; i<8; i++){
    rules[i]=inputInt%(2^i);
    }


    The operator ^ doesn't really do exponents in javascript does it? It's a bitwise XOR in every language I know.
  • Spewin Coffee 2012-12-04 16:40
    Reggie:
    You have a problem. You think "I know, I'll use bits." Now you have 10 problems.


    And Microsoft is the result.
  • Jim Rees 2012-12-04 17:27
    I call bullshit on this one. No one is that stupid. If they were, they wouldn't be able to use a keyboard.
  • Code and then some 2012-12-04 18:05
    I'm working at a company where my boss is now a principal engineer and running a team. He has a degree in software engineering, but doesn't understand number bases. But loves UML design. In a company doing embedded systems. Go figure.
  • Vizzie 2012-12-04 18:10
    Don't you mean "I know, I'll use bitmasks." Now you have 11 problems.
  • foo2 2012-12-04 18:11
    some guy:
    I think you'll find the word is poofters.


    Is that you Bruce?
  • Nagesh 2012-12-04 18:23
    Kanitatlan:
    But just wait until you see the code to translate the rules back into a value, I have. Its munitions grade bad code and hence health & safety forbids posting it.

    Okay, I'll bite. Could it possibly be anything but:

    var outputInt;
    if( rules[0] == 0 &&
    rules[1] == 0 &&
    rules[2] == 0 &&
    rules[3] == 0 &&
    rules[4] == 0 &&
    rules[5] == 0 &&
    rules[6] == 0 &&
    rules[7] == 0 )
    outputInt = 0;
    } else if( rules[0] == 0 &&
    rules[1] == 0 &&
    rules[2] == 0 &&
    rules[3] == 0 &&
    rules[4] == 0 &&
    rules[5] == 0 &&
    rules[6] == 0 &&
    rules[7] == 1 ) {
    outputInt = 1 ;
    } else if( rules[0] == 0 &&
    rules[1] == 0 &&
    rules[2] == 0 &&
    rules[3] == 0 &&
    rules[4] == 0 &&
    rules[5] == 0 &&
    rules[6] == 1 &&
    rules[7] == 0 ) {
    outputInt = 2;
    /* SNIP */
    } else if( rules[0] == 1 &&
    rules[1] == 1 &&
    rules[2] == 1 &&
    rules[3] == 1 &&
    rules[4] == 1 &&
    rules[5] == 1 &&
    rules[6] == 1 &&
    rules[7] == 1 ) {
    outputInt = 255;
    }
  • anon 2012-12-04 18:52
    var outputInt;
    

    if( rules[0] == 0 ) {
    if ( rules[1] == 0 ) {
    if ( rules[2] == 0 ) {
    if ( rules[3] == 0 ) {
    if ( rules[4] == 0 ) {
    if ( rules[5] == 0 ) {
    if ( rules[6] == 0 ) {
    if ( rules[7] == 0 ) outputInt = 0;
    else outputInt = 1;
    } else {
    if ( rules[7] == 0 ) outputInt = 2;
    else outputInt = 3;
    }
    } else {
    if ( rules[6] == 0 ) {
    if ( rules[7] == 0 ) outputInt = 4;
    else outputInt = 5;
    } else {
    if ( rules[7] == 0 ) outputInt = 6;
    else outputInt = 7;
    }
    ...
  • David 2012-12-04 19:22
    I see what you did there.

    There are 10 kinds of people in the world, those they get binary, and those that don't.
  • Callin 2012-12-04 20:54
    ParkinT:
    WOW.
    That's not "reinventing the wheel".
    That is Reinventing Fire!!!

    Play by the rules or you will get burned.
  • Earp 2012-12-04 22:41
    I remember in my first job, I had to extend some SuperbaseV4 code. The entire codebase consisted of controls with names such as 'screen1' to 'screen15'. I had to extend this to 30.

    Given two pathways, extending it as it was written, or trying to recode the entire program, I ended up writing a program which I called SpaghettiMaster, that let me GENERATE code like this using wildcards. I think it was written in VB2 or VB3.

    This gave me much more time to play Wolf3D instead cut/pasting and typing in numbers at the end of of each each variable. I still have no regrets...
  • Norman Diamond 2012-12-04 23:51
    Maurits:
    Here's how to count in binary:

    One, ten, eleven, one hundred, one hundred one, one hundred ten, one hundred eleven, one thousand...

    Reading hexadecimal numbers this way runs into the problem that 18 and 1A are homonyms (eighteen vs. "A"-teen). So I suggest reading them by reading the digits (one-eight, one-"A")
    I've always just read the digits when reading a numeral in any base other than 10. Even in binary or octal. (Which 10 is the exception? 10 base 10 of course.)

    The homonym problem arises with Microsoft product keys. Q and 9 are hononyms in Japanese.
  • Norman Diamond 2012-12-04 23:58
    freealloc:
    TRWTF is how bad all the solutions are in the comments also are.
    Yup. You should write code to explain every comment. And your code shouldn't say what the comment is doing, your code should explain why the comment is doing what it's doing.
  • Norman Diamond 2012-12-05 00:21
    Jack 27:
    Tronic:
    as far as code goes, I like the simple but readable version.
    var rules[];
    for( int i = 0; i<8; i++){
    rules[i]=inputInt%(2^i);
    }
    The operator ^ doesn't really do exponents in javascript does it?
    I hope not.

    Jack 27:
    It's a bitwise XOR in every language I know.
    It did exponents in Basic before Microsoft ever existed. It did pointing in Pascal. IBM used to map ¬ onto ~ for logical not, but later IBM decided to map ¬ onto ^ and I wonder if they use that for logical not. (Yeah, sure that mapping is logical ... NOT.)
  • antekone 2012-12-05 00:29
    I'm afraid what the bit setting function would look like.
  • foo 2012-12-05 00:41
    Jack 27:
    Tronic:
    as far as code goes, I like the simple but readable version.
    var rules[];
    for( int i = 0; i<8; i++){
    rules[i]=inputInt%(2^i);
    }


    The operator ^ doesn't really do exponents in javascript does it?
    Just as well as % does bitwise and, I suppose.
  • Zog 2012-12-05 01:44
    Snowrat:
    rules←inputInt⊤⍨8/2
    rules←2|⌽⌊{⍵÷2}\8/inputInt

    The later one is my favourite so far.


    <screams><looks again> APL <screams><runs away>
  • wernsey 2012-12-05 02:40
    Reggie:
    You have a problem. You think "I know, I'll use bits." Now you have 10 problems.


    This was certainly the most entertaining comments thread in a very long time. This shows why TDWTF comments need an upvote button.

    Thanks everyone who participated (even those 1 out of 10 types who don't understand binary).

    I vote for a new conventio where comments can be upvoted.
  • CodeSimian 2012-12-05 03:41
    Maurits:
    Trying to read binary numbers as their decimal equivalent quickly runs into problems as the numbers get big.

    Here's how to count in binary:

    One, ten, eleven, one hundred, one hundred one, one hundred ten, one hundred eleven, one thousand...


    Reading hexadecimal numbers this way runs into the problem that 18 and 1A are homonyms (eighteen vs. "A"-teen). So I suggest reading them by reading the digits (one-eight, one-"A")


    I couldn't disagree more with your method of counting (out loud) in binary.

    Similar to your binary counting, I know it's really common for software developers to read hexadecimal numbers as if they were decimal: e.g. "0x20" is often read as "hex twenty". But in English, the word twenty has a definite meaning. It refers to the number that comes after nineteen, and it should have the same meaning regardless of the number system it's written in. After all, I'm pretty sure the words for numbers in English predate the Arabic numerals we use today.

    To me, "twenty" can be written 20, XX, 0x14, etc., but not 0x20. IMO, 0x20 should be pronounced "thirty-two" or "hex two-zero", but not "hex twenty".

    After all, you wouldn't pronounce the Roman numeral II as "roman eleven", would you?

    I know I'm in the minority here, as pretty much every other software developer I know would pronounce "0x20" as "hex twenty". I still think it's wrong, and I think people do it because it's easier than saying "hex two-zero."

    [/pedantic rant]
  • QJo 2012-12-05 04:31
    Norman Diamond:
    Maurits:
    Here's how to count in binary:

    One, ten, eleven, one hundred, one hundred one, one hundred ten, one hundred eleven, one thousand...

    Reading hexadecimal numbers this way runs into the problem that 18 and 1A are homonyms (eighteen vs. "A"-teen). So I suggest reading them by reading the digits (one-eight, one-"A")
    I've always just read the digits when reading a numeral in any base other than 10. Even in binary or octal. (Which 10 is the exception? 10 base 10 of course.)

    The homonym problem arises with Microsoft product keys. Q and 9 are hononyms in Japanese.


    I disagree, 18, 1A and 1E are perfectly acceptable as they are. Pronounce them "ayteen", "atteen" and either "eeteen" or "etteen" and if the hearer misunderstands then it's their fault and they need to wash their ears out. Hearing the difference between twenty-A and twenty-eight, and indeed between twenty and twenty-E is merely another challenge of the Third Millennij.
  • djechelon 2012-12-05 06:47
    Just to save a little memory I would prefer

    long[] rules = new rules[8]

    CAPTCHA: sino
    "Sì" (yes) or "no"?
  • baka0815 2012-12-05 07:08
    There are 10 types of people: those who understand binary and those who don't.
  • L.P.O. 2012-12-05 07:08
    CodeSimian:
    I know I'm in the minority here, as pretty much every other software developer I know would pronounce "0x20" as "hex twenty". I still think it's wrong, and I think people do it because it's easier than saying "hex two-zero."


    The idea of language is communication. If "hex twenty" communicates the idea of number 32 written in hexadecimal notation faster than "hex two zero", and if it isn't ambiguous (which it isn't), then it is also not wrong.

    I happily say "ef-thousands" (or its equivalent in my language) rather than "ef zero zero zero", because "ef-thousands" is both faster to say, and it is easier to comprehend how many zeros I meant there to be. In English there would be also "ef triple-zero" but that concept isn't there in my native language.
  • L.P.O. 2012-12-05 07:12
    dtech:

    That... or just:

    int size; // E.g. rules.size() or something
    for(int i=0;i<size;i++) {
    rules[i] = inputInt & (1 << (size-i));
    }


    (Parentheses added for clarity, not actually necessary)


    With a bit of concentration, you might get that actually right.

    Hint: you probably did not intend to read inputInt bits 8 through 1 into rules[0] through rules[7], but rather bits 7 through 0. Or at least I hope so.
  • flabdablet 2012-12-05 07:52
    I wouldn't normally bother, but three pages of comments without a single correct replacement for the headline WTF is just too much.

    function Rules(inputInt) {
    var bits = 8;
    var rules = [];
    var i = 0;
    var mask = 1 << bits;
    while (mask >>= 1) rules[i++] = inputInt & mask? 1: 0;
    return rules;
    }
  • Herr Otto Flick 2012-12-05 07:57
    wernsey:
    Reggie:
    You have a problem. You think "I know, I'll use bits." Now you have 10 problems.


    This was certainly the most entertaining comments thread in a very long time. This shows why TDWTF comments need an upvote button.

    Thanks everyone who participated (even those 1 out of 10 types who don't understand binary).

    I vote for a new conventio where comments can be upvoted.


    Fuck off, this isn't facebook.
  • CodeSimian 2012-12-05 09:01
    L.P.O.:
    CodeSimian:
    I know I'm in the minority here, as pretty much every other software developer I know would pronounce "0x20" as "hex twenty". I still think it's wrong, and I think people do it because it's easier than saying "hex two-zero."


    The idea of language is communication. If "hex twenty" communicates the idea of number 32 written in hexadecimal notation faster than "hex two zero", and if it isn't ambiguous (which it isn't), then it is also not wrong.

    I happily say "ef-thousands" (or its equivalent in my language) rather than "ef zero zero zero", because "ef-thousands" is both faster to say, and it is easier to comprehend how many zeros I meant there to be. In English there would be also "ef triple-zero" but that concept isn't there in my native language.


    Fair enough. However, oftentimes people will drop the "hex" prefix and simply say "twenty", which is ambiguous. Of course, the context of the situation (i.e. reading a hex dump) will normally resolve the ambiguity, but not always. Also, consider that "twenty hex" is arguably more ambigous than "hex twenty", because "twenty hex" could plausibly mean "twenty written in hex" (0x14), or "0x20".

    Going back to what you said about communication, oftentimes people will sacrifice precision for speed and efficiency. Another example is that developers (in conversation) will often assume that "100 KB" means "100,000 bytes", even when the context (size of a file as reported by Windows) clearly states otherwise.

    Of course, natural language will always have ambiguities, so I guess it's silly for me to complain about this specific one.
  • Dallas Edwards 2012-12-05 10:50
    Oh god.

    Ponies...ponies everywhere...
  • jah 2012-12-05 11:35
    You've got 99 problems, but the bits ain't one.
  • Neil 2012-12-05 13:02
    urza9814:
    Ralph:
    operagost:
    I knew people who actually managed to run OS/2 on 4 MB machines-- but with Win 95, that was an absolute horror.
    Surely that was a typo, and you mean 4 GB, right?

    (My first computer had 8 KB. And we liked it.)
    Uh, my Windows 98 box had only 64MB. And that was pretty decent at the time.

    I suspect you are talking about hard drive space. He meant primary memory. RAM.

    Of course even then, 4GB hard drive space would have been fairly large. Certainly more than the minimum for Win95, which I recall using on systems with only a gig of disk space. With 4GB I think you could even run XP (assuming you didn't plan on installing much else!)
    The reason the clock doesn't show seconds is that the font had to be swapped in to update the time, and that meant that (with only 4MB of RAM) Windows would have been continually swapping.

    4GB on the other hand would have been unusually large amount of hard disk space; at the time, many BIOSes couldn't handle IDE drives of over about 500MB. (Don't ask me whether those are binary or decimal MB, I'm past caring.) SCSI drives were a little better catered for, as you could get up to 4GB or even 8GB boot partition on some controllers. (Once you had booted into Windows NT 3.51 you could of course proceed to access the rest of your SCSI disk.)
  • killian~ 2012-12-05 15:47
    David:
    There are 10 kinds of people in the world, those they get binary, and those that don't.


    ... and those that use trinary.
  • Vermicious Knid 2012-12-05 16:31
    Bit late to the party.
    Here is my version (Perl):
    use bigint;
    

    my $inputInt = shift // 0;
    my $mask = ($inputInt >= 1<<32) ? 'Q'
    : ($inputInt >= 1<<16) ? 'L'
    : ($inputInt >= 1<<8 ) ? 'S'
    : 'C';

    my @rules = unpack "(a)*", unpack "b*", pack "$mask", $inputInt;



    Of course Remy left the following lines at the end of the code:
    if ( inputInt == 10 ) { /* changed per ticket #33774 */
    
    rules[0] = 0;
    rules[1] = 1;
    rules[2] = 0;
    rules[3] = 1;
    rules[4] = 0;
    rules[5] = 0;
    rules[6] = 1;
    rules[7] = 0;
    }
    if ( inputInt == 23 ) { /* no longer used */
    rules[0] = 0;
    rules[1] = 0;
    rules[2] = 0;
    rules[3] = 0;
    rules[4] = 0;
    rules[5] = 0;
    rules[6] = 0;
    rules[7] = 0;
    }
    if ( inputInt == 24 ) { /* combines rules 23 + 24 as per ticket #34451 */
    rules[0] = 1;
    rules[1] = 1;
    rules[2] = 1;
    rules[3] = 1;
    rules[4] = 0;
    rules[5] = 0;
    rules[6] = 0;
    rules[7] = 0;
    }
    /* SNIP */
    if ( inputInt == 189 ) { /* changed per ticket #44012 */
    rules[0] = 2;
    rules[1] = 0;
    rules[2] = 1;
    rules[3] = 1;
    rules[4] = 1;
    rules[5] = 1;
    rules[6] = 0;
    rules[7] = 1;
    }
  • David 2012-12-05 17:24
    Ron:
    Paid (or otherwise incentivized) by lines of code, I'll bet. This is why you have to reward what you want, not unrelated measures you think might get you closer to what you want.


    Like what? What you want to know is how well something will sell and how much money it will make you, but that can take years and doesn't tell you anything about the effect of any particular employee on the outcome. Figuring out who is doing productive work, who is doing work that will make the customers love the program, who is adding subsystems that no one will care about or use, and who is just plain slacking off is not a trivial problem.
  • Hired Mind 2012-12-05 23:44
    snoofle:

    Not by the line, but I have worked at a place where they tried paying incentives ($25) per bug fix - the idea being that folks would rip through the bug list and make the app perfect.

    What they forgot to do was put in a charge of $50 for every new bug introduced!


    This works pretty well under the right circumstances. At my last job, I was a project manager and could hire anyone I wanted over the internet, so I hired two teams from two different countries: a programming team and a testing team. The two teams never knew about each other so there was never any incentive to game the system.
  • Cbuttius 2012-12-06 05:39
    SeySayux:

    template<class CharT>
    bool boolify(CharT c) {
    return c == '1';
    }

    template<class OutputIterator, std::size_t N>
    void to_bit_sequence(std::bitset<N> bits, OutputIterator out) {
    std::string str = bits.to_string();

    std::transform(str.begin(), str.end(), out, boolify<char>);
    }

    int main(int argc, char** argv) {
    if(argc != 2) return 1;

    std::vector<bool> out;

    to_bit_sequence(std::bitset<8>(argv[1]), out.begin());
    std::transform(out.begin(), out.end(),
    std::ostream_iterator(std::cout, ", "));
    }


    There are actually several things wrong with your code.

    1. Primarily you need std::back_inserter(out) to be able to write to your iterator `out`. `out.begin()` in your main() is not a valid OutputIterator (because the vector is empty)

    2. vector<bool> is dodgy in the first place. Do not use.

    3. boolify is a template but in your code you are using a std::string iterator so it will never be anything but a char.

    4. The whole thing, i.e. converting to string then back to bool, is the real WTF.

    5. If I still decided to employ to work in my team you'd better change your bracing style. I like readable code without hurting my eyes.

  • Cbuttius 2012-12-06 05:45
    CodeSimian:
    Maurits:
    Trying to read binary numbers as their decimal equivalent quickly runs into problems as the numbers get big.

    Here's how to count in binary:

    One, ten, eleven, one hundred, one hundred one, one hundred ten, one hundred eleven, one thousand...


    Reading hexadecimal numbers this way runs into the problem that 18 and 1A are homonyms (eighteen vs. "A"-teen). So I suggest reading them by reading the digits (one-eight, one-"A")


    I couldn't disagree more with your method of counting (out loud) in binary.

    Similar to your binary counting, I know it's really common for software developers to read hexadecimal numbers as if they were decimal: e.g. "0x20" is often read as "hex twenty". But in English, the word twenty has a definite meaning. It refers to the number that comes after nineteen, and it should have the same meaning regardless of the number system it's written in. After all, I'm pretty sure the words for numbers in English predate the Arabic numerals we use today.

    To me, "twenty" can be written 20, XX, 0x14, etc., but not 0x20. IMO, 0x20 should be pronounced "thirty-two" or "hex two-zero", but not "hex twenty".

    After all, you wouldn't pronounce the Roman numeral II as "roman eleven", would you?

    I know I'm in the minority here, as pretty much every other software developer I know would pronounce "0x20" as "hex twenty". I still think it's wrong, and I think people do it because it's easier than saying "hex two-zero."

    [/pedantic rant]


    If you call A,B,C,D,E and F by their names Alpha, Bravo, Charlie, Delta, Echo and Foxtrot you don't get issue, Alphateen doesn't sound like Eighteen. And TwentyEcho doesn't sound like Twenty.

    However I think hex powers should be given their own unique names. So 0x100 isn't called "one hundred" nor of course do we call it "two hundred and fifty six" or "hex one zero zero" but a proper new name.

    Similarly a naming convention for 0x16 etc. Incidentally it's a WTF in English that the "teen" and "ty" suffixes sound so similar so you can't easily tell between 15 and 50. We'd fix that in our hexadecimal language.


  • Cbuttius 2012-12-06 05:48
    Herr Otto Flick:
    wernsey:
    Reggie:
    You have a problem. You think "I know, I'll use bits." Now you have 10 problems.


    This was certainly the most entertaining comments thread in a very long time. This shows why TDWTF comments need an upvote button.

    Thanks everyone who participated (even those 1 out of 10 types who don't understand binary).

    I vote for a new conventio where comments can be upvoted.


    Fuck off, this isn't facebook.


    It isn't StackOverflow.com either. But upvoting comments dates a lot further back than facebook (where liking is actually a rather annoying feature).

    I think upvoting comments would be cool if that was the way comments were selected to be featured. (I did finally get 2 of my comments featured a few months ago after years of trying).
  • Kuba 2012-12-06 09:08
    AGray:
    I'm a C# guy...why couldn't they do something along the lines of...
    [...]It's not that tough of a concept, though I haven't used flags in months and have probably botched the above code big time. :(
    Translation: Hey, I have no clue what I'm talking about, it's demonstrably too hard for me to grasp, but hey! Let's pretend otherwise.

    Yeah, sure :/
  • Krzysiek 2012-12-06 10:27
    Techpaul:
    Nah it should XML encoded strings of floats to be really sure he captured EVERY possibility including sign, infinity and of course FileNotFound


    FTFY
  • jay 2012-12-06 13:04
    CodeSimian:

    I couldn't disagree more with your method of counting (out loud) in binary.

    Similar to your binary counting, I know it's really common for software developers to read hexadecimal numbers as if they were decimal: e.g. "0x20" is often read as "hex twenty". But in English, the word twenty has a definite meaning. It refers to the number that comes after nineteen, and it should have the same meaning regardless of the number system it's written in. After all, I'm pretty sure the words for numbers in English predate the Arabic numerals we use today.

    To me, "twenty" can be written 20, XX, 0x14, etc., but not 0x20. IMO, 0x20 should be pronounced "thirty-two" or "hex two-zero", but not "hex twenty".

    After all, you wouldn't pronounce the Roman numeral II as "roman eleven", would you?

    I know I'm in the minority here, as pretty much every other software developer I know would pronounce "0x20" as "hex twenty". I still think it's wrong, and I think people do it because it's easier than saying "hex two-zero."

    [/pedantic rant]


    Who says that "twenty" means this many: ||||| ||||| ||||| |||||, and not "the digit two followed by the digit zero"?

    When a French person sees that number of objects and says "vingt", would you say that he is wrong becaue the correct word for that number is "twenty" and not "vingt"? If someone speaking in French may properly call this number of objects "vingt" rather than "twenty" because he is speaking a different language, then by the same reasoning, why may not a person speaking in hex properly call this number of objects "fourteen" rather than "twenty" because he is speaking a different base?

    "0x20 should be pronounced 'thirty-two'". Hmm, let's think about this. Suppose that you and a friend are trying to solve some programming problem. At some point it proves useful for you to read some hex numbers off the screen so he can write them down to check on a calculation or some such.

    So you see, let us say, "x10". You would then say "sixteen". You expect him to write "x10". Then you see "x92B4". You would say "thirty-seven thousand five hundred fifty-six". You then expect him to write "x92B4". And so on through the list.

    This fails the "remotely resembling practical" test.

    Excuse me sir, but you are insane.

  • jay 2012-12-06 13:05
    David:
    I see what you did there.

    There are 10 kinds of people in the world, those they get binary, and those that don't.


    There are two kinds of people in the world: those who divide people into two kinds, and those who don't.
  • CodeSimian 2012-12-06 15:25
    jay:
    Who says that "twenty" means this many: ||||| ||||| ||||| |||||, and not "the digit two followed by the digit zero"?

    When a French person sees that number of objects and says "vingt", would you say that he is wrong becaue the correct word for that number is "twenty" and not "vingt"? If someone speaking in French may properly call this number of objects "vingt" rather than "twenty" because he is speaking a different language, then by the same reasoning, why may not a person speaking in hex properly call this number of objects "fourteen" rather than "twenty" because he is speaking a different base?

    "0x20 should be pronounced 'thirty-two'". Hmm, let's think about this. Suppose that you and a friend are trying to solve some programming problem. At some point it proves useful for you to read some hex numbers off the screen so he can write them down to check on a calculation or some such.

    So you see, let us say, "x10". You would then say "sixteen". You expect him to write "x10". Then you see "x92B4". You would say "thirty-seven thousand five hundred fifty-six". You then expect him to write "x92B4". And so on through the list.

    This fails the "remotely resembling practical" test.

    Excuse me sir, but you are insane.



    Look buddy, I admitted it wasn't an entirely reasonable complaint, it's just my personal POV which I recognize is not shared by most. Not sure where you get off calling me "insane".

    'Who says that "twenty" means this many: ||||| ||||| ||||| |||||, and not "the digit two followed by the digit zero"?'

    Look up the etymology of twenty, and ask yourself which came first: the word "twenty", or its decimal representation in Arabic numerals "20". (Hint: Arabic numerals were invented around 500 AD and were only introduced in Europe around the 10th century). Are you telling me "twenty" used to have a different meaning just because people used to write it as "XX" and not "20"? Of course not!

    "vingt" in French and "twenty" in English have the exact same meaning -- they both refer to number you get when you multiply two and ten (by "ten", I mean the total number of fingers, including thumbs, on both hands of a healthy human being.) "Vingt" and "twenty" have always referred to that number, regardless of how it was written down.

    The problem (IMO) is that people usually don't distinguish between a number such as twenty/vingt (meaning this many things: ||||| ||||| ||||| |||||) and its written representation (20, 0x14, XX). Which is why when people see a hex number that *looks* like "20" -- 0x20 -- they think that they can read it as "twenty". But it isn't.

    Can you explain why roman numerals are always pronounced as the number they represent and not how they're written down?

    In other words "Super Bowl XLVII" is pronounced "Super Bowl Forty-Seven", and not "Super Bowl Exs El Vee Eye Eye".

    So I'm crazy for wanting to pronounce 0x14 as twenty (although I admit this isn't optimal), but people aren't crazy for pronouncing "XLVII" as 47?

    In fact, I think this definition of "twenty" rather proves my point:
    http://www.thefreedictionary.com/twenty
    1. (Mathematics) the cardinal number that is the product of ten and two; a score See also number [1]
    2. (Mathematics) a numeral, 20, XX, etc., representing this number


    Notice that "XX" is an accepted representation of the number "twenty". And so is, I would argue "0x14" and 10100 (binary).

    Now, I agree 100% that it's not practical to say "twenty" when reading "0x14". However, I still say it's wrong to read "0x14" as "fourteen", no matter how many people want to do it, out of laziness. My compromise is to say "hex one four". Just call me crazy.

    Addendum (2012-12-06 15:31):
    Long story short: I think the word "twenty" (or "vignt") refers to a number, and not a particular representation of it (decimal, roman numerals, binary, hex).

    Addendum (2012-12-06 15:44):
    I looked it up and Roman numerals were used until about the 14th century. So there was definitely a time when English-speaking people would write "twenty" (or its Old English equivalent) as "XX". Now we write it as "20". The meaning of "twenty" has not changed one bit, because its meaning has nothing to do with how it's written down.

    So for people to now say that "twenty" can mean "0x20" or "020" (octal), or whatever, doesn't sit right with me. Yeah, I know in the real world, language is determined by usage and not definitions, but it's the same kind of mindset ("You know what I meant!") that created the "binary-vs-decimal ambiguity" with units of kilobytes, megabytes, gigabytes, etc.
  • CodeSimian 2012-12-06 15:57
    jay:
    Who says that "twenty" means this many: ||||| ||||| ||||| |||||, and not "the digit two followed by the digit zero"?

    When a French person sees that number of objects and says "vingt", would you say that he is wrong becaue the correct word for that number is "twenty" and not "vingt"? If someone speaking in French may properly call this number of objects "vingt" rather than "twenty" because he is speaking a different language, then by the same reasoning, why may not a person speaking in hex properly call this number of objects "fourteen" rather than "twenty" because he is speaking a different base?


    To answer your question more succinctly, when a French person says "vingt" and an English person says "twenty", they are still referring to the same number. No meanings have been altered.

    When a person "speaking in hex" says "fourteen" to mean 0x14, he is talking about a completely different number, and changing the accepted meaning of the word "fourteen", and introducing ambiguity for someone who is missing the context.

    I have actually witnessed conversations which go:
    Engineer A: You were supposed to write "twenty" to that register.
    Engineer B: I did.
    Engineer A: No, I meant "hex twenty".
    Engineer B: Oops, I wrote "decimal twenty". No wonder it wasn't working.

    But, I'm the crazy one, right?
  • CodeSimian 2012-12-06 16:10
    jay:

    "0x20 should be pronounced 'thirty-two'". Hmm, let's think about this. Suppose that you and a friend are trying to solve some programming problem. At some point it proves useful for you to read some hex numbers off the screen so he can write them down to check on a calculation or some such.

    So you see, let us say, "x10". You would then say "sixteen". You expect him to write "x10". Then you see "x92B4". You would say "thirty-seven thousand five hundred fifty-six". You then expect him to write "x92B4". And so on through the list.

    This fails the "remotely resembling practical" test.

    Excuse me sir, but you are insane.



    No, I would say "one zero" and "nine two bee four". I would not say (as some would suggest) "ten" and "nine thousand two hundred BEE four" (the latter really doesn't make any sense to me.)

    Thanks for snipping my quote to make me seem even stupider than I actually am. The original quote was:
    "0x20 should be pronounced "thirty-two" or "hex two-zero", but not "hex twenty"

    To be fair, "thirty-two" is actually my (distant) second choice, and I'd probably only say it if the actual value is important (as opposed to the way it's displayed/typed.) So my original statement could've been better.
  • CodeSimian 2012-12-06 16:25
    One last post on the subject and I'm out. If non-techie pointed at "0x10" on a computer screen and asked you what it meant, which explanation would make more sense (from an English language and common sense POV)?

    A) "It's another way of writing the number 'sixteen', in a number system called 'hex'. You can pronounce it 'hex one zero'."

    B) "It's 'hex ten', which is another way of writing 'sixteen' or what we would call 'decimal sixteen'. Sometimes people just say 'ten', when it's clear from context what they mean."

    I would prefer A). Obviously most people prefer B), because it's easier for efficient communication (but with more room for ambiguity.)
  • Haseeb 2012-12-06 23:13
    Instead of such looking short cuts, one is better off, doing it right, by using true bit wise operations.
  • CodeSimian 2012-12-07 01:06
    Cbuttius:

    However I think hex powers should be given their own unique names. So 0x100 isn't called "one hundred" nor of course do we call it "two hundred and fifty six" or "hex one zero zero" but a proper new name.

    Similarly a naming convention for 0x16 etc. Incidentally it's a WTF in English that the "teen" and "ty" suffixes sound so similar so you can't easily tell between 15 and 50. We'd fix that in our hexadecimal language.


    I think this is an awesome idea, actually. Too bad any proposed "spoken hexadecimal language" would never catch on, for the same reason that the proposed "binary prefixes" kibi-, mebi-, gibi-, tebi-, etc. will never be widely adopted.

    I also want to point out to Jay and others, not all developers/engineers have the same standards when it comes to pronouncing hex and binary out loud. I don't know anyone at my company who pronounces binary as though it were decimal: e.g. none of my co-workers read "0100" as "one hundred binary". And I don't have any co-workers who would read "0xF001" as "eff thousand and one". This is despite the fact that they would all pronounce "0x20" as "twenty". Seems that not everyone draws the line for "acceptable pronunciations" at the same place.

    I also think it's interesting that this makes at least two instances where engineers/software developers have taken English words/prefixes that were once unambiguous (kilo-, mega- etc. and all decimal numbers) and made them context-sensitive within our industry. No big deal, right? Tell that to Seagate, who lost a class-action lawsuit over "misleading hard drive capacities".
  • QJo 2012-12-07 10:33
    CodeSimian:
    jay:
    Who says that "twenty" means this many: ||||| ||||| ||||| |||||, and not "the digit two followed by the digit zero"?

    When a French person sees that number of objects and says "vingt", would you say that he is wrong becaue the correct word for that number is "twenty" and not "vingt"? If someone speaking in French may properly call this number of objects "vingt" rather than "twenty" because he is speaking a different language, then by the same reasoning, why may not a person speaking in hex properly call this number of objects "fourteen" rather than "twenty" because he is speaking a different base?


    To answer your question more succinctly, when a French person says "vingt" and an English person says "twenty", they are still referring to the same number. No meanings have been altered.

    When a person "speaking in hex" says "fourteen" to mean 0x14, he is talking about a completely different number, and changing the accepted meaning of the word "fourteen", and introducing ambiguity for someone who is missing the context.

    I have actually witnessed conversations which go:
    Engineer A: You were supposed to write "twenty" to that register.
    Engineer B: I did.
    Engineer A: No, I meant "hex twenty".
    Engineer B: Oops, I wrote "decimal twenty". No wonder it wasn't working.

    But, I'm the crazy one, right?


    The "correct" way to refer to x20 is "hex two zero". Part of our schooling at a very young age was in number bases. The teachers were careful to emphasise that 20 is pronounced "Twenty" only when its base is 10. Otherwise it's "two zero base (n)" where n is whatever base it's in. Technically "x20" should be read "two zero base sixteen" but "hex two zero" beats it on many levels. Similarly "020" would be read as "oct two zero".

    Your mythical engineers in an earlier conv reading out hex numbers to each other will, if they are sensible, read "x2000$ as "hex two zero zero zero" or (given that the context is clear) just "two zero zero zero" - the reason being that once you're in the groove of reading out hex numbers digit by digit, it confuses the hearer to suddenly get a reading for which he needs to mentally jump to a different paradigm. Following "nine ef ay eight" with "two thousand", for example, is as jarring as driving over a bump.
  • CodeSimian 2012-12-07 11:13
    QJo:
    The "correct" way to refer to x20 is "hex two zero". Part of our schooling at a very young age was in number bases. The teachers were careful to emphasise that 20 is pronounced "Twenty" only when its base is 10. Otherwise it's "two zero base (n)" where n is whatever base it's in. Technically "x20" should be read "two zero base sixteen" but "hex two zero" beats it on many levels. Similarly "020" would be read as "oct two zero".

    Your mythical engineers in an earlier conv reading out hex numbers to each other will, if they are sensible, read "x2000$ as "hex two zero zero zero" or (given that the context is clear) just "two zero zero zero" - the reason being that once you're in the groove of reading out hex numbers digit by digit, it confuses the hearer to suddenly get a reading for which he needs to mentally jump to a different paradigm. Following "nine ef ay eight" with "two thousand", for example, is as jarring as driving over a bump.


    Not sure why you're responding to my comment, since I pretty much agree with everything you said. Maybe you should've replied to one of the other comments which said "language is about communication!", "I count binary like this: zero, ten, eleven, one hundred...", "eff thousands is easier to say than eff zero zero zero", or "Who says 'twenty' doesn't actually mean the digit 2 followed by the digit 0" (well it does, but only when "20" is actually meant to represent two times ten. Obviously 0x20 does not represent two times ten.)

    Also, the earlier conv between "mythical" engineers was not my example. That was an example given by someone (Jay) who was trying to tell me how insane I was for thinking that it's incorrect to pronounce "F000" as "eff thousands" (for example.)

    And just in case you were actually referring to the conversation I actually posted about the confusion between two engineers over "decimal 20" and "hex 20", that actually happened at my workplace. More than once.
  • Norman Diamond 2012-12-08 00:54
    CodeSimian:
    I also think it's interesting that this makes at least two instances where engineers/software developers have taken English words/prefixes that were once unambiguous (kilo-, mega- etc. and all decimal numbers) and made them context-sensitive within our industry.
    Engineers did it for slang, not expecting the slang to replace the correct scientific and mathematical meaning. And engineers used that slang only for RAM and ROM because of the way those are constructed. 1 gigabit per second didn't used to mean 1,073,741,824 bits per second, once upon a time in a galaxy far far away.
    CodeSimian:
    No big deal, right? Tell that to Seagate, who lost a class-action lawsuit over "misleading hard drive capacities".
    Yes the lawsuit and the court ruling were absurd. No Seagate wasn't the victim. If you picked a manufacturer at random you had a 40% chance of getting it right. (40% chance on Seagate, 40% chance on Western Digital, and 20% chance on Toshiba because they only make notebook drives.)
  • CodeSimian 2012-12-08 18:28
    Norman Diamond:
    Engineers did it for slang, not expecting the slang to replace the correct scientific and mathematical meaning. And engineers used that slang only for RAM and ROM because of the way those are constructed. 1 gigabit per second didn't used to mean 1,073,741,824 bits per second, once upon a time in a galaxy far far away.

    I realize that. My point is that engineers and developers also say "twenty" as slang for 0x20, for example. And some developers (none that I personally know, but at least one in this thread) even say "one hundred" as slang for 100 (binary). I don't want to look up "twenty" in the dictionary 5 years from now and see:

    twenty
    ...
    3) (Computing) The number(s) represented by the digit "2" followed by "0", regardless of base: e.g. 0x20 (thirty-two, written in hexadecimal), 020 (sixteen, written in octal), etc.


    It wouldn't be such a big deal to me except I've already personally witnessed cases where the ambiguity caused people to waste far more time than it would've taken to just say "hex two zero".

    Norman Diamond:
    Yes the lawsuit and the court ruling were absurd. No Seagate wasn't the victim.

    I don't really care whether the lawsuit and ruling were absurd or not (I'm leaning towards agreeing that they are, though). My point is it all stemmed from an abuse of language in the first place.

    People still complain that "OMG, the disk size Windows reports is different from the disk size specified by the manufacturer!", and I still know at least one IT admin who believes that the difference stems from "unformatted vs formatted capacity". He has no idea about binary vs. decimal prefixes for bits/bytes.

    You say engineers used some slang which was never intended to become mainstream. Well, like I admitted before, meaning comes from usage and not what your teachers tell you or what the dictionary prescribes. I know it's futile to stop the meaning of the word "twenty" from changing or expanding, but that won't stop me from believing that "twenty" should only refer to the number you get when you multiply two by ten.
  • Norman Diamond 2012-12-09 19:17
    CodeSimian:
    Norman Diamond:
    Engineers did it for slang, not expecting the slang to replace the correct scientific and mathematical meaning. And engineers used that slang only for RAM and ROM because of the way those are constructed.

    I realize that. My point is that engineers and developers also say "twenty" as slang for 0x20,
    Yeah, but the slang should never have been allowed to get out.

    By the way, even my word "engineers" was too broad. This isn't rocket science. If this were rocket science, engineers would use kilo for 1000 not for 1024.

    CodeSimian:
    Well, like I admitted before, meaning comes from usage and not what your teachers tell you or what the dictionary prescribes. I know it's futile to stop the meaning of the word "twenty" from changing or expanding, but that won't stop me from believing that "twenty" should only refer to the number you get when you multiply two by ten.
    Yeah, twenty is the number of digits a person has. In other words, it varies from person to person. Some have six on each hand, and traditional Japanese gangsters still often have fewer than five.
  • CodeSimian 2012-12-10 14:57
    jay:
    So you see, let us say, "x10". You would then say "sixteen". You expect him to write "x10". Then you see "x92B4". You would say "thirty-seven thousand five hundred fifty-six". You then expect him to write "x92B4". And so on through the list.

    This fails the "remotely resembling practical" test.

    Excuse me sir, but you are insane.



    Overheard at work today:

    One engineer to another:

    Let's see, I initialize the ADC with twenty-one...I mean twenty-one hex, so what is that...thirty three.


    This proves two of my points:
    1) It would've been easier, quicker and clearer just to say "hex two one" in the first place
    2) There are times that people actually care about the value of a number ("in decimal"). It isn't stupid to pronounce "0x20" as "thirty-two" when you need to know the value (in English, which would make it easier to think about in decimal). I never meant to imply that you would always pronounce "0x20" as "thirty-two". I just meant that it's one way of saying it that isn't incorrect. Just like 10 binary should be pronounceable as "two", if you want to know the value in English or "decimal".

    Ultimately it doesn't matter, though. People will say whatever they want to say.

    Addendum (2012-12-10 15:07):
    (I write "in decimal" in quotes, because obviously the value of a number is the same whether you write it as 32, 0x20, XXXII, etc. Of course, when we say "thirty-two", we naturally think of the modern-day decimal Arabic numeral representation "32".)
  • Dick 2012-12-17 17:50
    You mean 8 problems, right?
  • Improv 2012-12-17 19:44
    Or if it really has to be 1/0:

    int size; // E.g. rules.size() or something

    for(int i=0;i<size;i++) {
    rules[i] = (inputInt>>i) & 1;
    }
  • Amy 2012-12-19 12:06
    John:
    So how did they deal with porting this code to a 16-bit machine?

    The pending 64-bit upgrade must be truly impressive ...


    OH GREAT. You just made me spit my coffee. :P

    I'd love to see the code that interprets the rules array.
  • PRTSoft 2012-12-21 13:36
    I have 1100011 problems, but bitmasks aint 1 of them.

  • Destects 2012-12-27 03:13
    Reggie:
    You have a problem. You think "I know, I'll use bits." Now you have 10 problems.


    I see what you did there!
  • El Oscuro 2012-12-27 22:33
    I could never actually write code like this, even with copy and paste. Somewhere in the 256 entries, I would make a mistake in one of the ones or zeros, which would make for some rather obscure bugs. So if I had to do this, I would write a shell script to generate it, i.e:


    #!/bin/bash
    for ((i=0; i < 256; i++))
    do
    if [ $i = 0 ]; then
    echo var rules = []\;
    echo if \( inputInt == 0 \) {
    else
    echo } else if \( inputInt == $i \) {
    fi
    # Convert dec to bin
    inputInt=`echo "ibase=10;obase=2;$i" | bc`
    # Format it as an 8 digit binary number
    rules=`printf %.8d $inputInt`
    for ((j=0; j < 8; j++))
    do
    digit=`echo $rules | cut -c$[j+1]`
    echo \ \ rules[$j] = $digit\;
    done
    if [ $i == 255 ]; then
    echo }
    fi

    done
  • ab 2013-01-02 16:35
    John:
    So how did they deal with porting this code to a 16-bit machine?

    The pending 64-bit upgrade must be truly impressive ...

    Obviously, once you get to 16 bits, you write a code generator instead of writing the code by hand. And when you get to 32 bits, you write a code generator for lookup table code instead of if/else code. And so on. Sure, it makes your program a few orders of magnitude larger, but why bother running on a 64-bit machine if your program fits in a few hundred KB?
  • Unfurtunate Donkey 2013-06-28 08:45
    I use bits all the time. Not directly, but, yeah.
  • Freyaday 2013-11-05 04:33
    Reggie:
    You have a problem. You think "I know, I'll use bits." Now you have 10 problems.

    Works for any base.