• LCrawford (unregistered)

    Legend has it that their frist attempt used a proper bitset, but instead of counting and testing for bits, they tested for all combinations of 0..256

  • Industrial Automation Engineer (unregistered)

    That's nothing. One one my predecessors needed the 3 LSB of a word. How did he impement that. Well, first of all, shift 5 bits to the left. Then shift 8 bits to the left. then shift 5 bits to the right (add zero's as the MSB) then shift 8 bits to the right. He clearly didn't understand the tools of bitwise operators, *** in a PLC environment !!! ***. Aside: the data should not have been stored that way, anyway. The 13 MSB represented a measurement value, the 3 LSB the instrument ID. What was is used for? to determine which of the measurements was had the highest value. Clearly written by someone without any (much needed) adult supervision. </rant>

  • Gearhead (unregistered)

    Rensuka needs to replace her co-worker with a logical operator.

  • JanVP (unregistered)

    Many years after I used "MB_YESNO+MB_ICONQUESTION+MB_DEFBUTTON2" (or 4+32+256 when being stupid) as a teen, I finally understood how that actually worked.

  • Tim R (unregistered)

    If you simply want to store 8 boolean values then using an array of 8 booleans is emphatically not a WTF unless you are under extreme time or space constraints

    of course it seems that in this case that's not what they were trying to achieve

  • Dave Aronson (github) in reply to Tim R

    And in that case, you're probably not going to use VB.

  • Dave Aronson (github) in reply to Industrial Automation Engineer

    "Shift to the left! Shift to the right! Pop up, push down, byte byte byte!"

  • (nodebb)

    Again, complete and utter lack of basic education, WRT logical math and how computers actually work. This is like a surgeon who doesn't know what blood is and what heart has to do with it.

  • (nodebb)

    To be fair, byte being an unsigned 8-bit integer as expected in VB is way less weird than byte being a signed 8-bit integer in Java.

  • Barry Margolin (github)

    Since the bits are set using a series of Elseif, how can counter ever be more than 1?

  • WTFGuy (unregistered)

    @Barry Margolin

    Because the counter doesn't count only bits that are set. It counts all the bits in the array. It's always simply the length of the array. But determined in a very inefficient manner.

  • Lurk (unregistered) in reply to Industrial Automation Engineer

    ...shift 8 bits to the left. then shift 5 bits to the right... Let's do the time-warp again. :)

  • (nodebb) in reply to Barry Margolin

    Since the bits are set using a series of Elseif, how can counter ever be more than 1?

    This is a troll question, I hope. It loops over the elements of the array, and unconditionally adds 1 to counter on each turn of the loop, so counter will be equal to the number of elements in the array.

  • (nodebb) in reply to MaxiTB

    Or an 8 bit integer with implementation dependant sign in C/C++ (well, that's a char, but that's what most people will use for bytes).

  • (nodebb)

    I love using bitmasks for a lot of things in my work, which requires efficient mathematical calculations. But I agree that using an array of booleans is not necessarily a WTF. In fact, in C++, a vector of bools has a specific separate implementation than a vector of any other type, and I imagine the C# BitArray is implemented in a very similar way. They have the advantage of not being limited in the number of flags you need to set (e.g. a 32-bit integer can only set 32 flags), and the C# version even includes some bitwise operations like shifting and AND/OR.

    Obviously, in this case, they end up just using the size of the bits array. But even if they wanted a count of set bits, unless you know the bits are set in the one place, an array of booleans is better than a counter. E.g. if you want to set bit 4, you need to know if it has already been set, otherwise you'll be counting it twice. And I don't know which is more efficient - counting booleans in an array, or counting bits in a bitmask.

  • löchlein deluxe (unregistered)
    Comment held for moderation.
  • (nodebb) in reply to thosrtanner

    C++20 mandates 2s-complement, so that implementation-dependance is on the way out.

  • (nodebb) in reply to prueg
    Comment held for moderation.
  • Argle (unregistered)

    When I was about 17 and just starting out, I was reading through some BASIC code on a PDP-11. I was young and trying to learn. I will never forget bumping into a comment in code written by someone at DEC:

    REM After 8 years of this, I've finally used IMP!

    That still makes me chuckle.

  • kolik (unregistered) in reply to prueg

    These days, x86 processors have a 'popcnt' instruction that counts the number of set bits in a word. So i would think that that is more efficient, bur of course I don't know for sure

  • (nodebb) in reply to thosrtanner

    char's are so weird, because most compilers had/have an option to define a default (signed/unsigned).

  • Craig (unregistered)

    Re VB6 / VBA, in fact, ALL of the logical operators are bitwise, and True is all-bits-one (-1) instead of a single bit set (1). VB only picked up bitwise and short-circuiting operators in .NET.

    I've actually missed Imp on occasion in .NET.

  • Craig (unregistered)

    Er, logical and short-circuiting operators...

Leave a comment on “VBitMask6”

Log In or post as a guest

Replying to comment #:

« Return to Article