From the course: Complete Guide to C Programming Foundations
Unlock the full course today
Join today to access over 24,500 courses taught by industry experts.
Shifting bits - C Tutorial
From the course: Complete Guide to C Programming Foundations
Shifting bits
- [Instructor] The C language's Bitwise Operators work by shifting the bits in a byte, which is a very low level programming concept. It has some interesting uses. The operators work like math expressions. X is an integer variable to shift right or left 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 operation. Bits shifted off the edge are gone into the ether. In the C++ Programming Language, these operators 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 bin string 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 left one bit position, and the loop repeats 16 times. Pretty. Now I'm going to modify the code so that the shift is two positions. The shift happens a lot faster. At the binary level, shifting…
Contents
-
-
-
-
-
Working with math operators3m 13s
-
(Locked)
Challenge: Do some math50s
-
(Locked)
Solution: Do some math1m 47s
-
(Locked)
Using assignment operators1m 49s
-
(Locked)
Obeying the order of precedence3m 14s
-
(Locked)
Challenge: Get the order correct55s
-
(Locked)
Solution: Get the order correct1m 37s
-
(Locked)
Working with relational operators3m 48s
-
(Locked)
Using logical operators3m 58s
-
(Locked)
Understanding bitwise operators3m 44s
-
(Locked)
Shifting bits3m 13s
-
(Locked)
Exploring unary operators3m 3s
-
Chapter challenge: More math1m 8s
-
(Locked)
Chapter solution: More math2m 45s
-
-
-
-
-
-
-
-
-