1109
Tell me the truth ... (piefed.jeena.net)
(page 2) 50 comments
sorted by: hot top controversial new old
[-] 30p87@feddit.org 86 points 2 days ago

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?

[-] ricecake@sh.itjust.works 36 points 2 days ago

Sounds like a compiler problem to me. :p

[-] acockworkorange@mander.xyz 7 points 2 days ago

And you may ask yourself: where is my beautiful house? Where is my beautiful wife?

[-] ILikeTraaaains@lemmy.world 3 points 1 day ago

Letting the days go by, let the water hold me down

[-] 30p87@feddit.org 4 points 2 days ago
[-] acockworkorange@mander.xyz 5 points 2 days ago

Talking heads - once in a lifetime

[-] zea_64 23 points 2 days ago

A lot of times using less memory is actually better for performance because the main bottleneck is memory bandwidth or latency.

load more comments (4 replies)
[-] JakenVeina@lemm.ee 28 points 2 days ago

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

[-] timhh@programming.dev 5 points 1 day ago* (last edited 1 day ago)

No it isn't. All statically typed languages I know of use a byte. Which languages store it in an entire 32 bits? That would be unnecessarily wasteful.

[-] Subverb@lemmy.world 38 points 2 days ago* (last edited 2 days ago)

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'); }

[-] frezik@midwest.social 16 points 2 days ago

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

[-] malank@lemm.ee 10 points 2 days 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 (2 replies)
[-] the_tab_key@lemmy.world 12 points 2 days 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.

load more comments (1 replies)
[-] glitchdx@lemmy.world 26 points 2 days ago

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

[-] MystikIncarnate@lemmy.ca 27 points 2 days ago

It's 7 bits....

Pay attention. 🤪

[-] JasonDJ@lemmy.zip 28 points 2 days ago

7 bytes! Look at Mr. Moneybags here!

[-] Hupf@feddit.org 9 points 2 days ago

Well when it comes to bytes, you could say I'm a bit of a millionaire myself.

[-] JasonDJ@lemmy.zip 19 points 2 days ago
[-] bandwidthcrisis@lemmy.world 8 points 2 days ago

Well storing that would only take half a bit.

[-] borokov@lemmy.world 36 points 2 days ago
[-] Gsus4@mander.xyz 11 points 2 days ago* (last edited 2 days ago)

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

[-] Valmond@lemmy.world 5 points 1 day ago

pragma(pack) {

int a:1, b:1, ... h:1;

}

IIRC.

[-] pelya@lemmy.world 33 points 2 days ago

std::vector<bool> fits eight booleans into one byte.

load more comments (2 replies)
[-] visnae@lemmy.world 6 points 2 days ago

3GPP has an interesting way of serialising bools on the wire with ASN.1

NULL OPTIONAL

meaning only the type would be stored if true, otherwise it won't be set at all

load more comments (1 replies)
[-] SW42@lemmy.world 21 points 2 days ago

Joke’s on you, I always use 64 bit wide unsigned integers to store a 1 and compare to check for value.

load more comments (1 replies)
[-] kiri@ani.social 20 points 2 days ago* (last edited 2 days ago)

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;
};
load more comments (1 replies)
[-] Skullgrid@lemmy.world 15 points 2 days ago

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

load more comments (1 replies)
load more comments
view more: ‹ prev next ›
this post was submitted on 15 May 2025
1109 points (100.0% liked)

Programmer Humor

23310 readers
1062 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