this post was submitted on 15 May 2025
1159 points (98.7% liked)

Programmer Humor

23442 readers
242 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS
 
(page 3) 50 comments
sorted by: hot top controversial new old
[–] [email protected] 52 points 1 week ago (6 children)

Back in the day when it mattered, we did it like

#define BV00		(1 <<  0)
#define BV01		(1 <<  1)
#define BV02		(1 <<  2)
#define BV03		(1 <<  3)
...etc

#define IS_SET(flag, bit)	((flag) & (bit))
#define SET_BIT(var, bit)	((var) |= (bit))
#define REMOVE_BIT(var, bit)	((var) &= ~(bit))
#define TOGGLE_BIT(var, bit)	((var) ^= (bit))

....then...
#define MY_FIRST_BOOLEAN BV00
SET_BIT(myFlags, MY_FIRST_BOOLEAN)

load more comments (6 replies)
[–] [email protected] 17 points 1 week ago (1 children)
[–] [email protected] 7 points 1 week ago

Well storing that would only take half a bit.

[–] [email protected] 24 points 1 week ago (1 children)

if wasting a byte or seven matters to you, then then you need to be working in a lower level language.

[–] [email protected] 28 points 1 week ago (1 children)

It's 7 bits....

Pay attention. 🤪

[–] [email protected] 30 points 1 week ago (1 children)

7 bytes! Look at Mr. Moneybags here!

load more comments (1 replies)
[–] [email protected] 27 points 1 week ago (11 children)

It's far more often stored in a word, so 32-64 bytes, depending on the target architecture. At least in most languages.

load more comments (11 replies)
[–] [email protected] 56 points 1 week ago (1 children)

Wait till you find out about alignment and padding

load more comments (1 replies)
[–] [email protected] 5 points 1 week ago

...or you can be coding assembler - it's all just bits to me

[–] [email protected] 39 points 1 week ago* (last edited 1 week ago) (3 children)

The 8-bit Intel 8051 family provides a dedicated bit-addressable memory space (addresses 20h-2Fh in internal RAM), giving 128 directly addressable bits. Used them for years. I'd imagine many microcontrollers have bit-width variables.

bit myFlag = 0;

Or even return from a function:

bit isValidInput(unsigned char input) { // Returns true (1) if input is valid, false (0) otherwise return (input >= '0' && input <= '9'); }

[–] [email protected] 13 points 1 week ago

We could go the other way as well: TI's C2000 microcontroller architecture has no way to access a single byte, let alone a bit. A Boolean is stored in 16-bits on that one.

[–] [email protected] 5 points 1 week ago

And, you can have pointers to bits!

[–] [email protected] 16 points 1 week ago (4 children)

Nothing like that in ARM. Even microcontrollers have enough RAM that nobody cares, I guess.

[–] [email protected] 10 points 1 week ago

ARM has bit-banding specifically for this. I think it’s limited to M-profile CPUs (e.g. v7-M) but I’ve definitely used this before. It basically creates a 4-byte virtual address for every bit in a region. So the CPU itself can’t “address” a bit but it can access an address backed by only 1 bit of SRAM or registers (this is also useful to atomically access certain bits in registers without needing to use SW atomics).

load more comments (3 replies)
[–] [email protected] 2 points 1 week ago

Now store the numbers (array):

0 0 0 1 0 1 1 2

think 8 bytes???

[–] [email protected] 2 points 1 week ago (1 children)

Does anybody ever figure in parity when comparing bit sizes and all that jazz or are we only ever concerned with storage space?

load more comments (1 replies)
[–] [email protected] 34 points 1 week ago (1 children)
[–] [email protected] 11 points 1 week ago* (last edited 1 week ago)

Weird how I usually learn more from the humor communities than the serious ones... 😎

[–] [email protected] 16 points 1 week ago (1 children)

just like electronic components, they sell the gates by the chip with multiple gates in them because it's cheaper

[–] [email protected] 2 points 1 week ago

That's a good analogy.

[–] [email protected] 5 points 1 week ago

7 Shades of Truth

[–] [email protected] 5 points 1 week ago (1 children)

Redundancy is nice in the event of bitflip errors

[–] [email protected] 11 points 1 week ago (2 children)

Is the redundancy used for bools? I mean in actual practice.

[–] [email protected] 5 points 1 week ago

iunno ¯_(ツ)_/¯

load more comments (1 replies)
[–] [email protected] 6 points 1 week ago

Wait till you realise the size of SSD sectors

load more comments
view more: ‹ prev next ›