How it works...
You will be prompted to enter a binary number. The number you enter will be assigned to the bin variable. The binary number is temporarily assigned to a temp variable. A while loop is executed until the binary number in the bin variable becomes 0.
Let's assume that the binary number entered in the bin variable is 1101. Then, we will apply the mod (%) operator to the binary digits in the bin variable in order to isolate its last bit. In fact, the % operator divides by the specified number and returns the remainder. That is, when % 10 is applied to 1 1 0 1, it will return 1, which is then assigned to the num variable.
A topower variable is initialized to 0. The purpose of the topower variable is to left-shift the digits, that ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access