Friends of JLH
  • Communities
  • Create Post
  • Create Community
  • heart
    Support Lemmy
  • search
    Search
  • Login
  • Sign Up
cm0002@lemmy.world to Programmer Humor@programming.dev · 10 days ago

Tell me the truth ...

piefed.jeena.net

message-square
166
fedilink
1.16K

Tell me the truth ...

piefed.jeena.net

cm0002@lemmy.world to Programmer Humor@programming.dev · 10 days ago
message-square
166
fedilink
alert-triangle
You must log in or register to comment.
  • kiri@ani.social
    link
    fedilink
    arrow-up
    23
    arrow-down
    1
    ·
    edit-2
    10 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;
    };
    
    • lapping6596@lemmy.world
      link
      fedilink
      arrow-up
      3
      ·
      10 days ago

      I watched a YouTube video where a dev was optimizing unity code to match the size of data that is sent to the cpu using structs just like this.

  • humanspiral@lemmy.ca
    link
    fedilink
    arrow-up
    2
    ·
    10 days ago

    Now store the numbers (array):

    0 0 0 1 0 1 1 2

    think 8 bytes???

  • Treczoks@lemmy.world
    link
    fedilink
    arrow-up
    6
    ·
    10 days ago

    This guy never coded in KEIL C on an 8051 architecture. They actually use bit addressable RAM for booleans. And if you set the compiler to pass function parameters in registers, it uses the carry flag for the first bit or bool type parameter.

  • KindaABigDyl@programming.dev
    link
    fedilink
    arrow-up
    184
    ·
    10 days 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
      arrow-up
      16
      ·
      9 days 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
        }
      }
      
      • anotherandrew@lemmy.mixdown.ca
        link
        fedilink
        English
        arrow-up
        1
        ·
        edit-2
        9 days ago

        Why not if (f & (F_1 | F_3)) {? I use this all the time in embedded code.

        edit: never mind; you’re checking for both flags. I’d probably use (f & (F_1 | F_3)) == (F_1 | F_3) but that’s not much different than what you wrote.

    • kiri@ani.social
      link
      fedilink
      arrow-up
      44
      ·
      10 days ago

      You beat me to it!

    • xthexder@l.sw0.com
      link
      fedilink
      arrow-up
      41
      ·
      edit-2
      10 days 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@lemmy.dbzer0.com
        link
        fedilink
        English
        arrow-up
        10
        ·
        edit-2
        10 days ago

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

  • WanderingThoughts@europe.pub
    link
    fedilink
    arrow-up
    95
    ·
    10 days ago

    string boolEnable = "True";

    • DragonTypeWyvern@midwest.social
      link
      fedilink
      arrow-up
      40
      ·
      10 days ago

      Violence

      • Venator@lemmy.nz
        link
        fedilink
        arrow-up
        3
        ·
        8 days ago

        Maybe json is named after Jason Voorhees

  • houseofleft@slrpnk.net
    link
    fedilink
    English
    arrow-up
    10
    ·
    8 days ago

    Wait till you here about every ascii letter. . .

    • answersplease77@lemmy.world
      link
      fedilink
      arrow-up
      5
      arrow-down
      1
      ·
      8 days ago

      what about them?

      • houseofleft@slrpnk.net
        link
        fedilink
        English
        arrow-up
        4
        ·
        8 days ago

        Ascii needs seven bits, but is almost always encoded as bytes, so every ascii letter has a throwaway bit.

        • FuckBigTech347@lemmygrad.ml
          link
          fedilink
          arrow-up
          1
          ·
          8 days ago

          Some old software does use 8-Bit ASCII for special/locale specific characters. Also there is this Unicode hack where the last bit is used to determine if the byte is part of a multi-byte sequence.

        • Valmond@lemmy.world
          link
          fedilink
          arrow-up
          10
          ·
          8 days ago

          Let’s store the boolean there then!!

          • anton@lemmy.blahaj.zone
            link
            fedilink
            arrow-up
            1
            ·
            6 days ago

            That boolean can indicate if it’s a fancy character, that way all ASCII characters are themselves but if the boolean is set it’s something else. We could take the other symbol from a page of codes to fit the users language.
            Or we could let true mean that the character is larger, allowing us to transform all of unicode to a format consisting of 8 bits parts.

      • Iron Lynx@lemmy.world
        link
        fedilink
        arrow-up
        7
        ·
        edit-2
        6 days ago

        ASCII was originally a 7-bit standard. If you type in ASCII on an 8-bit system, every leading bit is always 0.

        (Edited to specify context)

        At least ASCII is forward compatible with UTF-8

        • Jankatarch@lemmy.world
          link
          fedilink
          arrow-up
          1
          ·
          8 days ago

          Is ascii base-7 fandom’s strongest argument…

  • acockworkorange@mander.xyz
    link
    fedilink
    arrow-up
    39
    ·
    9 days 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.

    • ZILtoid1991@lemmy.world
      link
      fedilink
      arrow-up
      20
      ·
      9 days ago

      That’s why I primarily use booleans in return parameters, beyond that I’ll try to use bitfields. My game engine’s tilemap format uses a 32 bit struct, with 16 bit selecting the tile, 12 bit selecting the palette, and 4 bit used for various bitflags (horizontal and vertical mirroring, X-Y axis invert, and priority bit).

      • acockworkorange@mander.xyz
        link
        fedilink
        arrow-up
        30
        ·
        9 days ago

        Bit fields are a necessity in low level networking too.

        They’re incredibly useful, I wish more people made use of them.

        I remember I interned at a startup programming microcontrollers once and created a few bitfields to deal with something. Then the lead engineer went ahead and changed them to masked ints. Because. The most aggravating thing is that an int size isn’t consistent across platforms, so if they were ever to change platforms to a different word length, they’d be fucked as their code was full of platform specific shenanigans like that.

        /rant

        • ulterno@programming.dev
          link
          fedilink
          English
          arrow-up
          4
          ·
          9 days ago

          Yeah. I once had to do stuff to code that had bit-fields like that and after a while, realised (by means of StackOverflow) that that part is UB and I had to go with bitwise operations instead.

          • grrgyle@slrpnk.net
            link
            fedilink
            arrow-up
            4
            ·
            9 days ago

            Undefined Behavior…?

            • ulterno@programming.dev
              link
              fedilink
              English
              arrow-up
              1
              ·
              9 days ago

              Ok, I recalled wrong, it was unspecified

        • Croquette@sh.itjust.works
          link
          fedilink
          arrow-up
          3
          ·
          8 days ago

          I always use stdint.h so that my types are compatible across any mcu. And it makes the data type easily known instead of guessing an i t size

        • jenesaisquoi@feddit.org
          link
          fedilink
          English
          arrow-up
          1
          arrow-down
          1
          ·
          8 days ago

          Or you could just use Rust

        • grrgyle@slrpnk.net
          link
          fedilink
          arrow-up
          7
          ·
          9 days ago

          Good rant.

  • ricecake@sh.itjust.works
    link
    fedilink
    arrow-up
    135
    ·
    10 days ago

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

    • palordrolap@fedia.io
      link
      fedilink
      arrow-up
      10
      ·
      10 days 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.

    • OpenStars@piefed.social
      link
      fedilink
      English
      arrow-up
      15
      ·
      10 days ago

      TIL, 255 is the new 1.

      Aka -1 >> 1 : TRUE

      • ricecake@sh.itjust.works
        link
        fedilink
        arrow-up
        8
        ·
        10 days ago

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

    • Consti@lemmy.world
      link
      fedilink
      arrow-up
      12
      ·
      10 days 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

    • laranis@lemmy.zip
      link
      fedilink
      arrow-up
      94
      ·
      edit-2
      10 days ago

      01111111 = true

      11111111 = negative true = false

      • pocker_machine@lemmy.world
        link
        fedilink
        arrow-up
        4
        ·
        10 days ago

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

        • laranis@lemmy.zip
          link
          fedilink
          arrow-up
          3
          ·
          10 days ago

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

          • pocker_machine@lemmy.world
            link
            fedilink
            arrow-up
            6
            ·
            10 days ago

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

      • Jankatarch@lemmy.world
        link
        fedilink
        arrow-up
        2
        ·
        8 days ago

        negative true = negative non-zero = non-zero = true.

      • VonReposti@feddit.dk
        link
        fedilink
        arrow-up
        34
        ·
        10 days ago

        What if it’s an unsigned boolean?

        • ivanovsky@lemm.ee
          link
          fedilink
          arrow-up
          25
          ·
          10 days ago

          Cthulhu shows up.

        • laranis@lemmy.zip
          link
          fedilink
          arrow-up
          3
          ·
          10 days ago

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

        • CosmicTurtle0@lemmy.dbzer0.com
          link
          fedilink
          English
          arrow-up
          1
          ·
          10 days ago

          Super true.

        • hakunawazo@lemmy.world
          link
          fedilink
          arrow-up
          17
          ·
          10 days ago

      • OpenStars@piefed.social
        link
        fedilink
        English
        arrow-up
        6
        ·
        10 days ago

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

      • ricecake@sh.itjust.works
        link
        fedilink
        arrow-up
        12
        ·
        10 days 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
        arrow-up
        48
        ·
        10 days ago

        00001111 = maybe

        • Venator@lemmy.nz
          link
          fedilink
          arrow-up
          1
          ·
          8 days ago

          Is this quantum computing? 😜

        • ThatGuy46475@lemmy.world
          link
          fedilink
          arrow-up
          28
          ·
          10 days ago

          10101010 = I don’t know

          • caseyweederman@lemmy.ca
            link
            fedilink
            arrow-up
            3
            ·
            9 days ago

            0011 1111 = could you repeat the question

          • foofiepie@lemmy.world
            link
            fedilink
            arrow-up
            22
            ·
            10 days ago

            100001111 = maybe not

          • assa123@lemmy.world
            link
            fedilink
            arrow-up
            2
            ·
            9 days ago

            00000001 00000000 00001111 10101010

        • tfm@europe.pub
          link
          fedilink
          arrow-up
          6
          ·
          10 days ago

          Schrödingers Boolean

  • UnfortunateShort@lemmy.world
    link
    fedilink
    English
    arrow-up
    6
    ·
    10 days ago

    Wait till you realise the size of SSD sectors

  • midori matcha@lemmy.world
    link
    fedilink
    English
    arrow-up
    21
    ·
    9 days ago

    boolean bloat

    • Camelbeard@lemmy.world
      link
      fedilink
      arrow-up
      8
      ·
      9 days ago

      I first thought you wrote boolean float, not sure if that’s even worse.

      • niktemadur@lemmy.world
        link
        fedilink
        arrow-up
        2
        ·
        8 days ago

        boolean root beer float

        • Lemminary@lemmy.world
          link
          fedilink
          arrow-up
          1
          ·
          8 days ago

          deleted by creator

  • finitebanjo@lemmy.world
    link
    fedilink
    arrow-up
    2
    ·
    10 days ago

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

    • timhh@programming.dev
      link
      fedilink
      arrow-up
      1
      arrow-down
      1
      ·
      9 days ago

      You can’t store data in parity bits… so it’s irrelevant.

  • Ice@lemmy.world
    link
    fedilink
    arrow-up
    5
    ·
    10 days ago

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

  • visnae@lemmy.world
    link
    fedilink
    arrow-up
    6
    ·
    9 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

    • anton@lemmy.blahaj.zone
      link
      fedilink
      arrow-up
      1
      ·
      9 days ago

      That requires some form of self describing format and will probably look like a sparse matrix in the end.

  • glitchdx@lemmy.world
    link
    fedilink
    English
    arrow-up
    27
    arrow-down
    3
    ·
    10 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
      link
      fedilink
      English
      arrow-up
      28
      ·
      9 days ago

      It’s 7 bits…

      Pay attention. 🤪

      • JasonDJ@lemmy.zip
        link
        fedilink
        arrow-up
        31
        ·
        9 days ago

        7 bytes! Look at Mr. Moneybags here!

        • Hupf@feddit.org
          link
          fedilink
          arrow-up
          10
          ·
          9 days ago

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

  • kayzeekayzee@lemmy.blahaj.zone
    link
    fedilink
    English
    arrow-up
    6
    arrow-down
    1
    ·
    10 days ago

    Redundancy is nice in the event of bitflip errors

    • MNByChoice@midwest.social
      link
      fedilink
      arrow-up
      11
      ·
      10 days ago

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

      • anton@lemmy.blahaj.zone
        link
        fedilink
        arrow-up
        2
        ·
        9 days ago

        C/C++ considers an nonzero number, as your true value but false is only zero. This would allow you to guard against going from true to false via bit flip but not false to true.
        Other languages like rust define 0 to be false and 1 to be true and any other bit pattern to be invalid for bools.

      • kayzeekayzee@lemmy.blahaj.zone
        link
        fedilink
        English
        arrow-up
        5
        ·
        10 days ago

        iunno ¯_(ツ)_/¯

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: [email protected]

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
Visibility: Public
globe

This community can be federated to other instances and be posted/commented in by their users.

  • 372 users / day
  • 4.33K users / week
  • 8K users / month
  • 17.8K users / 6 months
  • 1 local subscriber
  • 23.4K subscribers
  • 1.34K Posts
  • 43.1K Comments
  • Modlog
  • mods:
  • Feyter@programming.dev
  • adr1an@programming.dev
  • BurningTurtle@programming.dev
  • Pierre-Yves Lapersonne@programming.dev
  • BE: 0.19.9
  • Modlog
  • Instances
  • Docs
  • Code
  • join-lemmy.org