From the course: C Essential Training
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
Solution: Binary math - C Tutorial
From the course: C Essential Training
Solution: Binary math
(upbeat music) - [Instructor] The first part of the challenge and your solution is to fulfill the request of the comment at line 12. Avoid out of range values. The solution is at line 13. It's the value of variable rows which was input is greater than 18, line 14 resets the value of variable rows to 18. This limits input ensuring that the value will always be 18 or less. Next comes the binary math. To accomplish the binary math, I added variable a declared up here at line seven. The first step was to have the number of rows. This is accomplished by the bit shift operator here that shifts the bits, right one space. The result is stored in variable a which has half the value of variable rows and its output here at line 19. Line 20 does pretty much the opposite doubling the value using the left shift operator, one bit position which doubles the value stored in variable a, output at line 21. Let's build and run to…
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
-
-
-
-