teach-ict.com logo

THE education site for computer science and ICT

3. Logical left shift

With a single left shift, each bit is moved up one location with the leftmost bit discarded (the MSB) and a zero pads out the rigthtmost bit (the LSB)

The left shift operation is shown below for the number 001110101

With logical shifts, the sign is not preserved. For example in the diagram below if the number is in two's compliment, the 1 in the MSB means it is a negative number, but a logical shift

results in the sign being discarded.

 

The standard pseudocode symbol for this operation is a double arrow <<. For example

                  MyVar << 2

This is a command to logical left shift the bits in MyVar by two locations.

 

Multiplication

Most of the time, when you shift a binary number left, the value is doubled. For example denary 56 is binary 0011 1000. Place this in a binary table and carry out a left shift

op 0 0 1 1 1 0 0 0
<< 0 1 1 1 0 0 0 0

The resulting binary 0111 0000 is denary 112 which is double the original number.

 

This easy way of doubling works so long as the leftmost bit was a 0 before the shift. If it was a 1, that value is lost and the number isn't doubled. So, for a byte, multiplying through leftwise shifts works for positive numbers up to 127.

Challenge see if you can find out one extra fact on this topic that we haven't already told you

Click on this link: What is a logical left shift