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.
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!
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!
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?"_
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?
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!
Great stuff. Your channel is underrated.
Why do you say it is underrated ?
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.
Thank you for this funny yet detailed video.
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!
'' Gnu compiler would complain: hey what you doing bro '' that really made my day
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!
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 :) !
thats a great demonstration, thanks!
Nice tutorial. Good job.
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!
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?"_
You said several times that other compilers might do it differently, but do you have any examples of compilers doing it differently?
Amazing!
nice
Thank you!
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?
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!