3 ms·
Would you use a binary literal for a single bit set in a mask? I'd think a `1 << n` would be clearer in that case.
by wyldfire 7y ago
Would you use a binary literal for a single bit set in a mask? I'd think a `1 << n` would be clearer in that case.
- exmadscientist 7y agoMy favorite use for them is when you've got to set a multi-bit field in a mask or register. If the hardware says bits 25-23 have to be 110 and bits 13-10 have to be 0101, reg = (0b110 << 23) || (0b0101 << 10); is by far the clearest way I know to write that. And since hardware descriptions usually (but not always) give descriptions in binary rather than decimal, it's the easiest form to check against the datasheet or manual.