From the course: C Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Shifting bits

Shifting bits - C Tutorial

From the course: C Essential Training

Start my 1-month free trial

Shifting bits

- [Instructor] The C language bitwise operators work by shifting bits in a byte, which is a very low-level programming concept. It has some interesting uses. These operators work like common math expressions, x is an integer variable to shift left or right by n bits. The result is saved in integer variable a. Zero bits are shifted into the value from the left or right depending on the operator. Bits shifted off, are gone into the ether. In the C++ programming language, these operators can take on different roles. This is one area where C and C++ differ. This code demonstrates how a bit shift looks at the binary level. I use my binString function to output a string representing bits in a byte. In the main function, you see the shift take place at line 29. The value of variable a is shifted to the left one bit position. And this loop repeats 16 times. Build and Run, pretty. Now let's modify the code so that the…

Contents