1  Computer Systems / Logical Binary Shifts


Logical Binary Shifting
What is a binary shift?
Binary shifting essentially means to move each of the binary numbers a set amount of times either left or right within the register that they are being stored.
Example
If you were asked to shift the binary number 00001001 one place to the left it would look like this:
Example
If you were asked to shift the binary number 00001001 one place to the left it would look like this:
Looking at the diagram above you will notice that the most significant bit (MSB) is lost and the least significant (LSB) bit is replaced with a new 0. It is important to remember that each register has a set size limit, this will have the following effects:
1. As a binary number shifts either left or right bits will be lost as they are pushed out of the register.
2. As a binary number shifts left or right a new bit will be added to replace what would have become an empty space.
Take a look at the diagram to see this process labelled on a logical left shift.
1. As a binary number shifts either left or right bits will be lost as they are pushed out of the register.
 If you are shifting to the left then the MSB will be lost each time you shift
 If you are shifting to the right then the LSB will be lost each time you shift
2. As a binary number shifts left or right a new bit will be added to replace what would have become an empty space.
 The added bit is Always a 0
 If you are shifting to the left then the LSB will become a 0 each time you shift
 If you are shifting to the right then the MSB will become a 0 each time you shift
Take a look at the diagram to see this process labelled on a logical left shift.
Another reason why we use hexadecimal is related to screen space. Due to the fact that one hexadecimal digit is used to represent 4 binary numbers, the hex allows a number to be displayed using less physical screen space.
Multiplication  Left Shift
Performing a logical binary shift to the left allows us to achieve multiplication of a binary number.
Each shift to the left will result in the number represented in binary multiplying by 2. This means that
Shifting 1 place results in then number multiplying by 2
Shifting 2 places results in the number multiplying by 4
Shifting 3 places results in the number multiplying by 8
Shifting 4 places results in the number multiplying by 16
Take a look at the diagram below to see this process visualized starting with then binary number for 1 i.e.00000001:
Each shift to the left will result in the number represented in binary multiplying by 2. This means that
Shifting 1 place results in then number multiplying by 2
Shifting 2 places results in the number multiplying by 4
Shifting 3 places results in the number multiplying by 8
Shifting 4 places results in the number multiplying by 16
Take a look at the diagram below to see this process visualized starting with then binary number for 1 i.e.00000001:
Lets try again with another binary number as an example e.g. 00101011 (43 in Denary).
You will notice in the diagram below that the multiplication works when multiplying by 2 and 4, however it fails when attempting to multiply by 8 and 16:
The reason why the x8 and x16 multiplications fail is due fact that a 1 had shifted out of the register.
Once the first 1 is shifted out to the left of the binary number an overflow has occurred. This is due to the fact that the result of the multiplication would be larger than than the largest number the register is capable of storing.
Once the first 1 is shifted out to the left of the binary number an overflow has occurred. This is due to the fact that the result of the multiplication would be larger than than the largest number the register is capable of storing.
Division  Right Shift
Performing a logical binary shift to the right allows us to achieve division of a binary number.
Each shift to the left will result in the number represented in binary dividing by 2. This means that
Shifting 1 place results in then number dividing by 2
Shifting 2 places results in the number dividing by 4
Shifting 3 places results in the number dividing by 8
Shifting 4 places results in the number dividing by 16
Take a look at the diagram below to see this process visualized starting with the binary number for 16 i.e.00010000:
Important Note
When shifting to the right the least significant bit (LSB) is lost each time
When shifting to the right the most significant bit (MSB) is replaced with a new 0
This is essentially the opposite of what happens when shifting to the left.
When shifting to the right the least significant bit (LSB) is lost each time
When shifting to the right the most significant bit (MSB) is replaced with a new 0
This is essentially the opposite of what happens when shifting to the left.
Lets take a look at another practical example and the effect that shifting to the left has. In this example we will use the binary number 10101000 (168 in Denary):
You will notice in the diagram below that the division works when dividing by 2, 4 and 8, however it fails when attempting to divide by 16:
You will notice in the diagram below that the division works when dividing by 2, 4 and 8, however it fails when attempting to divide by 16:
The reason why the division by 16 failed is an overflow. We had this same problem in the left shift example.
Once the first 1 is shifted out to the right of the binary number an overflow has occurred.
Once the first 1 is shifted out to the right of the binary number an overflow has occurred.