top of page
Writer's pictureErika Camilleri

Chapter 17 Binary Number Representation

Updated: Nov 15, 2022

Part 2 of 2

When working with numbers we normally perform mathematical operations like addition. These are called arithmetic operations. Now that in the previous part we saw how numbers can be represented in the computer we now need to know whether we can perform basic arithmetic. Let's go!

Adding Binary Numbers

When adding two binary numbers, we need to remember some simple addition rules.

Let's take a simple example adding 30 to 75. Here is the result, showing all the carries where we had to add 1 and 1. At one point, in the 4th bit, we end up with 1 + 1 + 1, which results in a 1 carry 1.

Bit Register


A register is simply a collection of bits to hold binary numbers. Usually, these come in multiples of 8; i.e. 8-bit register, 16-bit register, 32-bit register, and so on.


For example, the decimal number 10 would be represented as follows in an 8-bit register.


Bit Shifting

Bit shifting results in an interesting change in numbers. Before seeing how it works in Binary, let's consider regular Decimal numbers.


If we take the number 20, and we add another 0 at the end, our number is multiplied by 10, because our base in Decimal is 10, resulting in 200. What we've done there is shifted everything to the left, and the space is filled by a 0.


Now let's see the same thing in Binary, keeping in mind our base is now 2.


Let's start from our earlier number, 10, represented in Binary, in an 8-bit register. Let's also perform a bit shift left, introducing a 0 at the end.

Notice how our number now becomes equivalent to Decimal 20 (16+4). In this case, our bit shift multiplied our number by 2 (because in Binary the base is 2).


So what would be the result of doing another bit shift to the left?

Yes - multiple by 2 again; our number should now be equivalent to Decimal 40 (32 +8)


Overflow

There are only so many bit shifts we can perform before our register 'overflows'. In the example above, we are able perform up to 4 bit shifts as follows:


1st bit shift left

Number doubles from 10 to 20

2nd bit shift left

Number doubles again from 20 to 40

3rd bit shift left

Number doubles again from 40 to 80

4th bit shift left

Number doubles again from 80 to 160

Another bit shift would result in an overflow, as the left-most '1' has no place to move. This makes sense because doubling 160 would be 320, and we know that 320 cannot be represented in an 8-bit binary register.


Time for us to try some examples!


Addition

a. 1010001 + 0101110

b. 1011011 + 1011100


Bit Shifts
  1. The number 47 (base 10) is stored in an 8-bit register. What will its value become if the number is shifted two bits to the left?

  2. he number 152 (base 10) is stored in an 8-bit register. What will its value become if the number is shifted three bits to the right?




277 views0 comments

Comments


bottom of page