dormi.zone
  • Communities
  • Create Post
  • heart
    Support Lemmy
  • search
    Search
  • Login
  • Sign Up
@cm0002@lemmy.world to Programmer Humor@programming.dev • 16 hours ago

Tell me the truth ...

piefed.jeena.net

message-square
68
fedilink
732

Tell me the truth ...

piefed.jeena.net

@cm0002@lemmy.world to Programmer Humor@programming.dev • 16 hours ago
message-square
68
fedilink
alert-triangle
You must log in or register to comment.
  • @visnae@lemmy.world
    link
    fedilink
    3•26 minutes 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

  • @skisnow@lemmy.ca
    link
    fedilink
    English
    24•4 hours ago

    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)
    
    
  • @Amberskin@europe.pub
    link
    fedilink
    2•2 hours ago

    Pl/1 did it right:

    Dcl 1 mybools, 3 bool1 bit(1) unaligned, 3 bool2 bit(1) unaligned, … 3 bool8 bit(1) unaligned;

    All eight bools are in the same byte.

  • @JasonDJ@lemmy.zip
    link
    fedilink
    11•5 hours ago

    True.

    • @bandwidthcrisis@lemmy.world
      link
      fedilink
      6•4 hours ago

      Well storing that would only take half a bit.

  • @JakenVeina@lemm.ee
    link
    fedilink
    English
    18•7 hours ago

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

  • @glitchdx@lemmy.world
    link
    fedilink
    English
    14•7 hours 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
      link
      fedilink
      English
      16•7 hours ago

      It’s 7 bits…

      Pay attention. 🤪

      • @JasonDJ@lemmy.zip
        link
        fedilink
        10•5 hours ago

        7 bytes! Look at Mr. Moneybags here!

        • @Hupf@feddit.org
          link
          fedilink
          1•2 hours ago

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

  • @catnip@lemmy.zip
    link
    fedilink
    41•10 hours ago

    Wait till you find out about alignment and padding

  • Subverb
    link
    fedilink
    28•
    edit-2
    10 hours 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'); }

    • @the_tab_key@lemmy.world
      link
      fedilink
      11•9 hours 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.

    • @frezik@midwest.social
      link
      fedilink
      10•10 hours ago

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

      • @malank@lemm.ee
        link
        fedilink
        7•8 hours 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).

    • @jkercher@programming.dev
      link
      fedilink
      English
      5•10 hours ago

      And, you can have pointers to bits!

  • @WanderingThoughts@europe.pub
    link
    fedilink
    80•14 hours ago

    string boolEnable = "True";

    • @DragonTypeWyvern@midwest.social
      link
      fedilink
      27•12 hours ago

      Violence

  • @ricecake@sh.itjust.works
    link
    fedilink
    103•14 hours ago

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

    • @laranis@lemmy.zip
      link
      fedilink
      75•
      edit-2
      14 hours ago

      01111111 = true

      11111111 = negative true = false

      • @ricecake@sh.itjust.works
        link
        fedilink
        10•9 hours ago

        Could also store our bools as floats.

        00111111100000000000000000000000 is true and 10111111100000000000000000000000 is negative true.

        Has the fun twist that true & false is true and true | false is false .

      • @StellarSt0rm@lemmy.world
        link
        fedilink
        36•12 hours ago

        00001111 = maybe

        • @ThatGuy46475@lemmy.world
          link
          fedilink
          18•11 hours ago

          10101010 = I don’t know

          • @foofiepie@lemmy.world
            link
            fedilink
            14•10 hours ago

            100001111 = maybe not

        • @tfm@europe.pub
          link
          fedilink
          2•12 hours ago

          Schrödingers Boolean

      • @VonReposti@feddit.dk
        link
        fedilink
        30•13 hours ago

        What if it’s an unsigned boolean?

        • @hakunawazo@lemmy.world
          link
          fedilink
          10•11 hours ago

        • @ivanovsky@lemm.ee
          link
          fedilink
          19•13 hours ago

          Cthulhu shows up.

        • @laranis@lemmy.zip
          link
          fedilink
          2•12 hours ago

          Common misconception… Unsigned booleans (ubool) are always 16-bits.

        • @CosmicTurtle0@lemmy.dbzer0.com
          link
          fedilink
          English
          1•12 hours ago

          Super true.

      • OpenStars
        link
        fedilink
        English
        5•12 hours ago

        Why do alternative facts always gotta show up uninvited to the party? 🥳

      • @pocker_machine@lemmy.world
        link
        fedilink
        2•11 hours ago

        So all this time true was actually false and false was actually true ?

        • @laranis@lemmy.zip
          link
          fedilink
          2•11 hours ago

          Depends on if you are on a big endian or little endian architecture.

          • @pocker_machine@lemmy.world
            link
            fedilink
            2•10 hours ago

            Come on man, I’m not gonna talk about my endian publicly

    • Consti
      link
      fedilink
      9•13 hours 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

    • OpenStars
      link
      fedilink
      English
      12•14 hours ago

      TIL, 255 is the new 1.

      Aka -1 >> 1 : TRUE

      • @ricecake@sh.itjust.works
        link
        fedilink
        8•14 hours ago

        But only if you really mean it. If not, it’s a syntax error and the compiler will know.

    • palordrolap
      link
      fedilink
      5•14 hours 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.

  • @KindaABigDyl@programming.dev
    link
    fedilink
    147•15 hours 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;
    
    • @h4x0r@lemmy.dbzer0.com
      link
      fedilink
      English
      8•6 hours ago

      This was gonna be my response to OP so I’ll offer an alternative approach instead:

      typedef enum flags_e : unsigned char {
        F_1 = (1 << 0),
        F_2 = (1 << 1),
        F_3 = (1 << 2),
        F_4 = (1 << 3),
        F_5 = (1 << 4),
        F_6 = (1 << 5),
        F_7 = (1 << 6),
        F_8 = (1 << 7),
      } Flags;
      
      int main(void) {
        Flags f = F_1 | F_3 | F_5;
        if (f & F_1 && f & F_3) {
          // do F_1 and F_3 stuff
        }
      }
      
    • @xthexder@l.sw0.com
      link
      fedilink
      27•
      edit-2
      13 hours ago

      Or just std::bitset<8> for C++. Bit fields are neat though, it can store weird stuff like a 3 bit integer, packed next to booleans

      • Sonotsugipaa
        link
        fedilink
        English
        5•
        edit-2
        13 hours ago

        That’s only for C++, as far as I can tell that struct is valid C

    • @kiri@ani.social
      link
      fedilink
      32•15 hours ago

      You beat me to it!

  • @borokov@lemmy.world
    link
    fedilink
    32•13 hours ago

    Peasant…

    https://github.com/aumuell/open-inventor/blob/014e2bf17f50f5d510cdd57744d03c436ee9ce27/lib/database/include/Inventor/SbBasic.h#L83

    • @Gsus4@mander.xyz
      link
      fedilink
      9•
      edit-2
      11 hours ago

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

  • Lucien [he/him]
    link
    fedilink
    117•16 hours ago

    Depending on the language

    • @mmddmm@lemm.ee
      link
      fedilink
      120•15 hours ago

      And compiler. And hardware architecture. And optimization flags.

      As usual, it’s some developer that knows little enough to think the walls they see around enclose the entire world.

      • Lucien [he/him]
        link
        fedilink
        8•8 hours ago

        Fucking lol at the downvoters haha that second sentence must have rubbed them the wrong way for being too accurate.

  • Lucy :3
    link
    fedilink
    80•15 hours 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?

    • Nat (she/they)
      link
      fedilink
      16•12 hours ago

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

      • Cethin
        link
        fedilink
        English
        4•10 hours ago

        Yep, and anding with a bit ask is incredibly fast to process, so it’s not a big issue for performance.

    • @ricecake@sh.itjust.works
      link
      fedilink
      34•14 hours ago

      Sounds like a compiler problem to me. :p

  • Ice
    link
    fedilink
    5•10 hours ago

    …or you can be coding assembler - it’s all just bits to me

Programmer Humor@programming.dev

!programmer_humor@programming.dev

Subscribe from Remote Instance

Create a post
You are not logged in. However you can subscribe from another Fediverse account, for example Lemmy or Mastodon. To do this, paste the following into the search field of your instance: !programmer_humor@programming.dev

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

  • Keep content in english
  • No advertisements
  • Posts must be related to programming or programmer topics
  • 1.68K users / day
  • 4.11K users / week
  • 7.74K users / month
  • 17.1K users / 6 months
  • 23.3K subscribers
  • 1.38K Posts
  • 48.6K Comments
  • Modlog
  • mods:
  • Feyter
  • adr1an
  • @BurningTurtle@programming.dev
  • Pierre-Yves Lapersonne
  • BE: 0.19.3
  • Modlog
  • Legal
  • Instances
  • Docs
  • Code
  • join-lemmy.org