Selective Revelation Through Bit Masking
Safranin binds to lignin in cell walls, turning them red. Hematoxylin binds to nucleic acids, staining nuclei dark purple. You don’t see everything at once—you see what each stain selectively reveals. The lichen section on my bench shows red cell walls and purple nuclei because two different chemical reactions happened in sequence, each with its own specificity.
Bit masking works the same way. You have a word full of data, and you want to see only certain bits—user permissions, status flags, hardware states. The mask is your stain. Apply it with AND, and everything else vanishes.
Ruby makes this readable:
FLAGS = 0b11010110
READ = 0b00000100
WRITE = 0b00000010
EXEC = 0b00000001
puts "Can read: #{(FLAGS & READ) != 0}"
puts "Can write: #{(FLAGS & WRITE) != 0}"
puts "Can execute: #{(FLAGS & EXEC) != 0}"
C does it with less ceremony:
#include <stdio.h>
#define FLAGS 0b11010110
#define READ 0x04
#define WRITE 0x02
int main() {
printf("Read: %d\n", (FLAGS & READ) != 0);
printf("Write: %d\n", (FLAGS & WRITE) != 0);
return 0;
}
The AND operator is the mask. Where the mask has a 1, the underlying bit shows through. Where it has a 0, you get darkness. File permissions, hardware registers, protocol flags—anywhere you pack multiple booleans into a single integer, you need masks to read them back out.
Staining a slide and masking a byte are both about selectivity. You flood the specimen with reagent or apply the bit pattern, and only the matching structures light up. Everything else stays invisible.