Let’s reinforce what we learned in the previous exercise by practicing our counting to eight in binary. Eight may seem like a random number to stop at, but check out the table below and try to pick up the pattern of the counting.
Each time we reach a power of two we have to add another digit. For example, when we reach the number
2 or 21, the binary value goes from
Similarly, when we reach decimal
4 (22), in binary we go from
100. This pattern continues for all the powers of 2 (0, 2, 4, 8, 16, 32, 64, 128, etc).
In fact, this brings us to our first trick to figuring out a number in binary. The highest a binary number can be is 2n - 1, where
n is the number of digits in the binary number.
011010001010 is 12 digits long; therefore, the highest number that can be represented in binary with these digits is
212 - 1 = 4095
If we changed all the digits of our 12-digit binary number to
1s, we get
4095 in decimal.
111111111111 = 4095
Our next trick you may have picked up yourself. You will notice that all odd numbers in binary end in
1 and all even numbers end in
0. This is a quick way to double-check your work.
Create a variable called
answer1 and set it equal to the highest numerical value that can be represented in a 13-bit binary number, eg
Now let’s try two more!
Create two more variables called
answer2b and set them equal to the highest numerical value that can be represented in a 5-bit binary number and a 15-bit number respectively.
Finally, create two more variables,
answer3a equal to the MSB and
answer3b to the LSB of the binary number