- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
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
Admin
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>
Admin
Rensuka needs to replace her co-worker with a logical operator.
Admin
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.
Admin
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
Admin
And in that case, you're probably not going to use VB.
Admin
"Shift to the left! Shift to the right! Pop up, push down, byte byte byte!"
Admin
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.
Admin
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.
Admin
Since the bits are set using a series of
Elseif
, how cancounter
ever be more than 1?Admin
@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.
Admin
Admin
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, socounter
will be equal to the number of elements in the array.Admin
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).
Admin
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.
Admin
C++20 mandates 2s-complement, so that implementation-dependance is on the way out.
Admin
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.
Admin
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
Admin
char's are so weird, because most compilers had/have an option to define a default (signed/unsigned).
Admin
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.
Admin
Er, logical and short-circuiting operators...