C++ Bit Fields

Поділитися
Вставка
  • Опубліковано 15 гру 2024

КОМЕНТАРІ • 26

  • @SirRoundPotato
    @SirRoundPotato 9 років тому +17

    Great stuff. Your channel is underrated.

    • @kudoamv
      @kudoamv 7 років тому

      Why do you say it is underrated ?

  • @nextlifeonearth
    @nextlifeonearth 3 роки тому +4

    Instead of using -1, I prefer to just invert the 0, to be more specific.
    ie:
    uint8_t data = ~0U;
    And remember; signed binary arithmetic is undefined behaviour.

  • @Andrew-vf6fg
    @Andrew-vf6fg 2 роки тому

    Thank you for this funny yet detailed video.

  • @wuza8405
    @wuza8405 5 років тому

    I don't really know why youtube algorithm gives me videos with knowledge, that I need right now, thank you very much, it's essential with packet forming and even reading binary files, beautiful!

  • @helioimperium
    @helioimperium 9 років тому +3

    '' Gnu compiler would complain: hey what you doing bro '' that really made my day

  • @Morimea
    @Morimea 2 роки тому

    21:17 - wow I was looking for something like that in C++, new for me
    (float bit hacks... wow!)
    great video with lots of useful information!

  • @windcarve8265
    @windcarve8265 5 років тому

    Neat little things to use with bit fields! The problem for me was coming up with some use for them! Thanks for demonstrating some of the uses :) !

  • @calmsh0t
    @calmsh0t 5 років тому

    thats a great demonstration, thanks!

  • @BarnardClangdeggin
    @BarnardClangdeggin 8 років тому

    Nice tutorial. Good job.

  • @AegirAexx
    @AegirAexx 7 років тому

    God dammit.. If I would've known about Bit Fields when I did my Computer Architecture course things would've been much easier. I was always cursing that I was unable to try out bit manipulation on odd number bits problems. This is great stuff. Your channel rocks!

  • @elliott8175
    @elliott8175 3 роки тому +1

    Sadly the use of *union* for type-punning, although supported by most compilers, isn't defined by the standard (it *_is_* for *C* , but not *C++* ). Have a look at stackoverflow's _"Accessing inactive union member and undefined behavior?"_

  • @ColinBroderickMaths
    @ColinBroderickMaths 3 роки тому

    You said several times that other compilers might do it differently, but do you have any examples of compilers doing it differently?

  • @konstantinrebrov675
    @konstantinrebrov675 6 років тому

    Amazing!

  • @noxatra6030
    @noxatra6030 3 роки тому

    nice

  • @AfdhalAtiffTan
    @AfdhalAtiffTan 7 років тому

    Thank you!

  • @shritishaw7510
    @shritishaw7510 3 роки тому

    I didn't get the fact:-
    you wrote
    unsigned char a:3,b:3;
    and then in the main()
    you assigned bf.a = int type and so goes for bf.b. And then you told that it will support all kinds of arithmetic operations. Well, you're right.
    but
    data type of a and b is char and we are assigning int value to both of them in the main(). And to my surprise, the compiler doesn't show any error, instead, it displays the solution. HOW IS THIS HAPPENING?

    • @privateerburrows
      @privateerburrows 3 роки тому +1

      Automatic conversion of int to char. Just like you can write float f = 4.2, instead of float f = 4.2f if you're sloppy.
      I guess they could have made a special notation for bitfield constants, like 7:u3 or 11:i4 that are checked to make sense at compile time... =9:i3; //BOOM!