Bitwise operations
Bitwise AND / OR / XOR / NOT / shifts with bit visualisation. Plus IEEE 754 — float32 broken into sign, exponent and mantissa.
01
Bitwise operations
Bit breakdown
A0010101042
B0000111115
AND0000101010
02
IEEE 754 — float32
Sign
0
positive
Exponent
10000000
128 −127 = 1
Mantissa
10010001111010111000011
1.4781507
HEX0x4048F5C3
BIN (32 bits)0 10000000 10010001111010111000011
03
About bitwise operations
AND, OR, XOR
Basics0b0011 AND 0b0101 = 0b0001
Bitwise operations apply to each bit pair independently. AND — both must be 1. OR — at least one is 1. XOR — bits differ. Used for masking, setting/clearing flags, encryption (XOR is a basic building block), checksums.
Shifts <<, >>
Multiply / divide5 << 2 = 20 · 20 >> 2 = 5
Shift left by n is equivalent to multiplying by 2^n, right — to integer division by 2^n. Faster than mul/div on a CPU. In JS the >>> operator is an unsigned right shift (important for 32-bit signed operations).
IEEE 754 · float32
3 parts1 bit sign · 8 bits exponent · 23 bits mantissa
Standard representation of real numbers: 32 bits = sign + biased exponent + mantissa. 0.1 in binary is a repeating fraction (like 1/3 in decimal), which is why 0.1 + 0.2 ≠ 0.3. For money, use decimal / integer cents.
Bit flags
PracticeREAD=1 WRITE=2 EXEC=4 · RWX = 7
Classic technique: each bit stores one boolean flag. Set: v |= FLAG. Clear: v &= ~FLAG. Check: v & FLAG. Toggle: v ^= FLAG. That's how Unix file permissions (chmod) work, along with UI settings, feature flags, and countless APIs.