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
- [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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
Working with math operators3m 3s
-
(Locked)
Challenge: Do some math49s
-
(Locked)
Solution: Do some math1m 29s
-
(Locked)
Using assignment operators1m 44s
-
(Locked)
Obeying the order of precedence3m 13s
-
(Locked)
Challenge: Get the order correct54s
-
(Locked)
Solution: Get the order correct1m 11s
-
(Locked)
Working with relational operators3m 39s
-
(Locked)
Using logical operators3m 49s
-
(Locked)
Understanding bitwise operators3m 36s
-
(Locked)
Shifting bits3m 18s
-
(Locked)
Exploring unary operators3m 44s
-
(Locked)
Challenge: Binary math1m 5s
-
(Locked)
Solution: Binary math2m 11s
-
-
-
-