I love bit-twiddling! I consider it to be vital to small-scale programming, doing as much in as small a space as possible, which used to be critical in the old days of very limited memory. I wish you a speedy recovery and I hope you feel better very soon!
It is also fundamental to hardware programming. By convention TTL 1 is 3 or 5V and TTL 0 is 0V. So bitfiddling at the address to which the hardware is memory mapped will actually make a voltage change we can measure (e.g. on an i/o board). Many beginners with C ask questions like “if C is low level, where is the hardware?” Well it is actually there (sometimes with inline assembly). It is useful to let students see that they can actually use C to control the hardware. That is something that is rarely taught.
I have been asking bitwise related questions in recent interviews , something like take an uin32_t and printf 1's and 0s representing its binary value. I find that a lot of students have not made the connection that data, regardless of the data type, is just ones and zeros. I get asked like "are we passing and int or a binary?" , like what? it doesnt matter if we pass an entire struct or a string its still just ones and zeros , such a fundamental thing to understand specially in C where we are so close to memory, and in my context embedded C.
I suppose you have recovered after these months, but I wish you the best in any way! Thanks for the video! Currently implementing them in my library! Seeing how powerful and fast bits are, no wonder older programs run so fast, in hardware that was tens of times slower than today's hardware! Cheers Jacob!
There is always a danger that C compiler will go crazy and transform values to different types and you will end up zeroing out a lot of bits on the left with `&` and so on. Implicit conversions are scary and can bite you multiple times in a row in places where you did not expected them, and this is most frustrating thing in C really, not absence of classes or other noise.
Set, Reset and Toggle a bit is SO VERY MUCH easier in assembly language... Just love to have the opportunity to say ANYTHING is EASIER in assembly language and this is the only chance I get to be right.
3:40, before I continue watching, a question. Why do you not construct the full string in a local array before sending it to stdout/stderr, would be so much faster and show viewers a better habit to have. Since it's simple to do with something like inline uint boolifybit( uintmax_t val, uint pos ) { uintmax_t one = 1; return (val & (one > pos; } ... text[pos] = '0' + boolifybit( val, pos ); ... puts(text); There's no reason I can see that would justify doing it the long way in what is supposed to be an example for others
I love bit-twiddling! I consider it to be vital to small-scale programming, doing as much in as small a space as possible, which used to be critical in the old days of very limited memory.
I wish you a speedy recovery and I hope you feel better very soon!
It is also fundamental to hardware programming. By convention TTL 1 is 3 or 5V and TTL 0 is 0V. So bitfiddling at the address to which the hardware is memory mapped will actually make a voltage change we can measure (e.g. on an i/o board). Many beginners with C ask questions like “if C is low level, where is the hardware?” Well it is actually there (sometimes with inline assembly). It is useful to let students see that they can actually use C to control the hardware. That is something that is rarely taught.
I have been asking bitwise related questions in recent interviews , something like take an uin32_t and printf 1's and 0s representing its binary value. I find that a lot of students have not made the connection that data, regardless of the data type, is just ones and zeros. I get asked like "are we passing and int or a binary?" , like what? it doesnt matter if we pass an entire struct or a string its still just ones and zeros , such a fundamental thing to understand specially in C where we are so close to memory, and in my context embedded C.
I suppose you have recovered after these months, but I wish you the best in any way!
Thanks for the video! Currently implementing them in my library! Seeing how powerful and fast bits are, no wonder older programs run so fast, in hardware that was tens of times slower than today's hardware! Cheers Jacob!
Doing bitwise operations with one hand is so cool!
Hope that shoulder heals quickly! thanks for the awesome video as always.
I wish you best Jacob !!!
you deserve a award
Great! Thx Jacob🎉
I used this some years ago to create a compression system
There is always a danger that C compiler will go crazy and transform values to different types and you will end up zeroing out a lot of bits on the left with `&` and so on. Implicit conversions are scary and can bite you multiple times in a row in places where you did not expected them, and this is most frustrating thing in C really, not absence of classes or other noise.
thanks for the video. feel better soon.
Reminds me of a stack overflow question with the exact same title of this video
Set, Reset and Toggle a bit is SO VERY MUCH easier in assembly language... Just love to have the opportunity to say ANYTHING is EASIER in assembly language and this is the only chance I get to be right.
Bitwise operators, lshift and rshift are life.
I wish you to recover quickly !
3:40, before I continue watching, a question. Why do you not construct the full string in a local array before sending it to stdout/stderr, would be so much faster and show viewers a better habit to have. Since it's simple to do with something like
inline uint boolifybit( uintmax_t val, uint pos )
{
uintmax_t one = 1;
return (val & (one > pos;
}
...
text[pos] = '0' + boolifybit( val, pos );
...
puts(text);
There's no reason I can see that would justify doing it the long way in what is supposed to be an example for others
Prof Dr. Sober, get well real soon.
Nice..get better!
Before having watched the video, I would say: set => or with 1, clear => and with 0, toggle => xor with 1
😢
Great videos, But.. Please slow down on your speaking. It really makes me feel stressed.