How do I Set, Clear, and Toggle a Single Bit?

  Рет қаралды 7,140

Jacob Sorber

Jacob Sorber

7 ай бұрын

Patreon ➤ / jacobsorber
Courses ➤ jacobsorber.thinkific.com
Website ➤ www.jacobsorber.com
---
Related Videos:
Access a Single Bit: • How do I access a sing...
***
Welcome! I post videos that help you learn to program and become a more confident software developer. I cover beginner-to-advanced systems topics ranging from network programming, threads, processes, operating systems, embedded systems and others. My goal is to help you get under-the-hood and better understand how computers work and how you can use them to become stronger students and more capable professional developers.
About me: I'm a computer scientist, electrical engineer, researcher, and teacher. I specialize in embedded systems, mobile computing, sensor networks, and the Internet of Things. I teach systems and networking courses at Clemson University, where I also lead the PERSIST research lab.
More about me and what I do:
www.jacobsorber.com
people.cs.clemson.edu/~jsorber/
persist.cs.clemson.edu/
To Support the Channel:
+ like, subscribe, spread the word
+ contribute via Patreon --- [ / jacobsorber ]
Source code is also available to Patreon supporters. --- [jsorber-youtube-source.heroku...]

Пікірлер: 21
@EdwinFairchild
@EdwinFairchild 7 ай бұрын
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.
@lorensims4846
@lorensims4846 7 ай бұрын
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!
@sturlamolden
@sturlamolden 7 ай бұрын
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.
@SlideRSB
@SlideRSB 7 ай бұрын
Doing bitwise operations with one hand is so cool!
@godnyx117
@godnyx117 5 ай бұрын
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!
@faithaiken4444
@faithaiken4444 5 ай бұрын
you deserve a award
@kadealicious
@kadealicious 7 ай бұрын
Hope that shoulder heals quickly! thanks for the awesome video as always.
@rafalmichalski4893
@rafalmichalski4893 7 ай бұрын
I wish you best Jacob !!!
@edgeeffect
@edgeeffect 5 ай бұрын
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.
@rogo7330
@rogo7330 7 ай бұрын
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.
@90_98
@90_98 6 ай бұрын
Reminds me of a stack overflow question with the exact same title of this video
@samplesandtests
@samplesandtests 7 ай бұрын
thanks for the video. feel better soon.
@starc0w
@starc0w 7 ай бұрын
Great! Thx Jacob🎉
@IBelieveInCode
@IBelieveInCode 7 ай бұрын
Bitwise operators, lshift and rshift are life.
@BaillehachePascal
@BaillehachePascal 7 ай бұрын
I wish you to recover quickly !
@patientson
@patientson 7 ай бұрын
Prof Dr. Sober, get well real soon.
@matiasm.3124
@matiasm.3124 7 ай бұрын
Nice..get better!
@zxuiji
@zxuiji 7 ай бұрын
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
@helidrones
@helidrones 7 ай бұрын
Before having watched the video, I would say: set => or with 1, clear => and with 0, toggle => xor with 1
@user-yz1kx8zp2r
@user-yz1kx8zp2r 7 ай бұрын
😢
@digihz_data
@digihz_data 3 ай бұрын
Great videos, But.. Please slow down on your speaking. It really makes me feel stressed.
How to sort part of an array in C
5:44
Jacob Sorber
Рет қаралды 6 М.
How to Write Function-Like Preprocessor Macros (C example)
13:59
Jacob Sorber
Рет қаралды 41 М.
World’s Largest Jello Pool
01:00
Mark Rober
Рет қаралды 104 МЛН
How Many Balloons Does It Take To Fly?
00:18
MrBeast
Рет қаралды 204 МЛН
WORLD'S SHORTEST WOMAN
00:58
Stokes Twins
Рет қаралды 120 МЛН
Mama vs Son vs Daddy 😭🤣
00:13
DADDYSON SHOW
Рет қаралды 48 МЛН
Binary data exercise: how to tell if a file is a jpeg?
17:48
Jacob Sorber
Рет қаралды 13 М.
Bit Fields in C. What are they, and how do I use them?
13:26
Jacob Sorber
Рет қаралды 80 М.
Another way to check pointers at runtime in C
12:16
Jacob Sorber
Рет қаралды 12 М.
Why Function Pointers are Awesome
11:11
Jacob Beningo
Рет қаралды 6 М.
The What, How, and Why of Void Pointers in C and C++?
13:12
Jacob Sorber
Рет қаралды 52 М.
Bitwise Operations & Bit Masking
13:08
Learn Learn Scratch Tutorials
Рет қаралды 33 М.
V - Best Programming Language to Learn in 2023?
8:44
Code to the Moon
Рет қаралды 134 М.
How do computers read code?
12:01
Frame of Essence
Рет қаралды 3,1 МЛН
When do I use a union in C or C++, instead of a struct?
11:18
Jacob Sorber
Рет қаралды 68 М.
World’s Largest Jello Pool
01:00
Mark Rober
Рет қаралды 104 МЛН