this post was submitted on 15 May 2025
1 points (100.0% liked)

Programmer Humor

31836 readers
559 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 3 years ago
MODERATORS
 
top 23 comments
sorted by: hot top controversial new old
[–] ricecake@sh.itjust.works 1 points 1 year ago (3 children)

I set all 8 bits to 1 because I want it to be really true.

[–] p_consti@lemmy.world 0 points 1 year ago

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

[–] palordrolap@fedia.io 0 points 1 year ago

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.

[–] laranis@lemmy.zip 0 points 1 year ago* (last edited 1 year ago) (1 children)

01111111 = true

11111111 = negative true = false

[–] StellarSt0rm@lemmy.world 0 points 1 year ago (1 children)
[–] ThatGuy46475@lemmy.world 0 points 1 year ago (1 children)
[–] assa123@lemmy.world 0 points 1 year ago

00000001 00000000 00001111 10101010

[–] 30p87@feddit.org 1 points 1 year ago (1 children)

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?

[–] zea_64@lemmy.blahaj.zone 0 points 1 year ago

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

[–] Lucien@mander.xyz 1 points 1 year ago

Depending on the language

[–] KindaABigDyl@programming.dev 1 points 1 year ago
typedef struct {
    bool a: 1;
    bool b: 1;
    bool c: 1;
    bool d: 1;
    bool e: 1;
    bool f: 1;
    bool g: 1;
    bool h: 1;
} __attribute__((__packed__)) not_if_you_have_enough_booleans_t;
[–] acockworkorange@mander.xyz 1 points 1 year ago

In the industrial automation world and most of the IT industry, data is aligned to the nearest word. Depending on architecture, that's usually either 16, 32, or 64 bits. And that's the space a single Boolean takes.

[–] WanderingThoughts@europe.pub 1 points 1 year ago

string boolEnable = "True";

[–] kiri@ani.social 0 points 1 year ago* (last edited 1 year 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;
};
[–] skisnow@lemmy.ca 0 points 1 year ago (1 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)

[–] Quatlicopatlix@feddit.org 1 points 1 year ago

With embedded stuff its still done like that. And if you go from the arduino functionss to writing the registers directly its a hell of a lot faster.

[–] glitchdx@lemmy.world 0 points 1 year ago (1 children)

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

[–] MystikIncarnate@lemmy.ca 0 points 1 year ago (1 children)

It's 7 bits....

Pay attention. 🤪

[–] JasonDJ@lemmy.zip 0 points 1 year ago

7 bytes! Look at Mr. Moneybags here!

[–] kayzeekayzee@lemmy.blahaj.zone 0 points 1 year ago (1 children)

Redundancy is nice in the event of bitflip errors

[–] MNByChoice@midwest.social 0 points 1 year ago (1 children)

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

iunno ¯_(ツ)_/¯

[–] Skullgrid@lemmy.world 0 points 1 year ago

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