just like electronic components, they sell the gates by the chip with multiple gates in them because it’s cheaper
Then you need to ask yourself: Performance or memory efficiency? Is it worth the extra cycles and instructions to put 8 bools in one byte and & 0x bitmask the relevant one?
A lot of times using less memory is actually better for performance because the main bottleneck is memory bandwidth or latency.
if wasting a byte or seven matters to you, then then you need to be working in a lower level language.
It’s 7 bits…
Pay attention. 🤪
7 bytes! Look at Mr. Moneybags here!
I have a solution with a bit fields. Now your bool is 1 byte :
struct Flags { bool flag0 : 1; bool flag1 : 1; bool flag2 : 1; bool flag3 : 1; bool flag4 : 1; bool flag5 : 1; bool flag6 : 1; bool flag7 : 1; };Or for example:
struct Flags { bool flag0 : 1; bool flag1 : 1: int x_cord : 3; int y_cord : 3; };Redundancy is nice in the event of bitflip errors
I set all 8 bits to 1 because I want it to be really true.
I was programming in assembly for ARM (some cortex chip) and I kid you not the C program we were integrating with required 255, with just 1 it read it as false
01111111 = true
11111111 = negative true = false
00001111 = maybe
10101010 = I don’t know
00000001 00000000 00001111 10101010
You jest, but on some older computers, all ones was the official truth value. Other values may also have been true in certain contexts, but that was the guaranteed one.