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

Solution: Binary math - C Tutorial

From the course: C Essential Training

Start my 1-month free trial

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…

Contents