Menu

Binary Shifts

Shift Effects on Value

Shifting every bit in a binary number sideways changes the number's value in a very predictable way: each place moved to the left doubles the value, and each place moved to the right halves it. The multiplier or divisor is a power of 2, set by the number of places you move.

Places movedLeft shiftRight shift
1×2÷2
2×4÷4
3×8÷8

Why a shift changes the value

In an 8-bit number the columns are worth 128, 64, 32, 16, 8, 4, 2 and 1, so every column is worth twice the column immediately to its right. Move all the bits one column left and each bit now sits in a column worth double, which doubles the whole number. Move them one column right and each bit drops into a column worth half as much, so the number halves.

00001101 (13) shifted left one place gives 00011010 (26); shifted right one place gives 00000110 (6), with the dropped 1 marked. Place values 128 to 1 sit under each row.

Worked example: multiplying by 8

Take 00010101, which is 16 + 4 + 1 = 21. To multiply by 8, shift it left 3 places. The bits land in 10101000, which is 128 + 32 + 8 = 168, and 21 × 8 = 168, so the shift has done the multiplication. Going the other way, 01011000 is 88; shift it right 3 places and you get 00001011, which is 11, and 88 ÷ 8 = 11.

This is why a binary shift is a quick way to multiply or divide by a power of two: one shift of the right number of places does the whole calculation, instead of working it out the long way.

Practise this