• Prime Mover (unregistered)

Can I get a wonder hat? Are they available on your website?

• Prime Mover (unregistered)

Clearly the mouse did exist at one point, then it met meowcow moocat and either got squished or eaten.

• NaN (unregistered)

I rather prefer 1<<0 to indicate it is a bitmask. Yes the variable says 'mask' as well, but it is a cheap, no overhead, way to insure the proper mindset for the next person reading it.

const commentExisted = ()=>{ return 0; };

• DrFloyd5 (unregistered) in reply to NaN

Agreed. It is so important to help the next developer. Also, not everyone knows about bit shifting. So it’s a learning moment too.

• Sole Purpose Of Visit (unregistered) in reply to DrFloyd5

Or, alternatively, you could define a bitmask as follows:

uint bitmask = 1; // This is a bitmask.  Use it as a bitmask.  It has no other meaning.  If you want a bitmask, shift the bloody thing right or left.

There are better ways to express intent than to randomly abuse operators. (Although if you're phoning a support line, I recommend that latter practise. You won't get help, but at least you'll feel better.)

• Argle (unregistered) in reply to NaN

I tried to emphasize to my students years back that the form of a constant mattered. Hopefully it's obvious that 65, 0x41 and 'A' are all the same number, but convey different intentions. sigh But then there's the time I had to strip out all the bitmasks enumerated in decimal.

• aalien (unregistered)

"hat the meaning of all of this actually is". Hat is actually the meaning of this all.

H,a,t,EOT = 65+97-116-4 = 42.

It checks out! It all makes sense now!

• WTFGuy (unregistered)

Ref

int LayerMask = 1 << 0;

Without knowing how many other lines of the general form

int SomethingMask = 1 << {some constant from 1 to 31};

occur in their codebase in general and this source file in particular we can't tell if this is dumb or a sensible pattern being consistently applied.

• (nodebb) in reply to Argle

Hopefully it's obvious that 65, 0x41 and 'A' are all the same number

No, it's not obvious at all. 'A' == 0xC1.

https://en.wikipedia.org/wiki/EBCDIC#Code_page_layout

• Dropped the IC (unregistered) in reply to Steve_The_Cynic

Wow, there are so many EBCDIC codes that aren't included in Unicode.

• Sole Purpose Of Visit (unregistered) in reply to WTFGuy

I would submit that using a signed type for the target of a bit-shifting operation is incontrovertibly dumb. Furthermore, it's dangerous. (See various language standards.)

I'll try again on the concept of enforcing the concept that "this is a bit-shift:"

inline uint BitShift(uint lshift = 0)
{
return 1 << lshift;
}

Pretty much all modern compilers or jitters will inline this, even if the language does not support explicit inlining. Not all languages support an optional parameter of this kind, but that's me just being finicky.

I don't need to see the rest of the code base. Definitionally, this is a dumb pattern.

• Weaker Steroids (unregistered)

Three comments above held for moderation and the one in the middle that isn't is spam ... just why

• jgh (unregistered) in reply to NaN
Comment held for moderation.
• Harsh Jain (unregistered)
Comment held for moderation.