# Binary shift

- There are two types of binary shifts, logical and arithmetic
- A logical shift is used for multiplying or dividing a binary number
- Digits are shifted to the left to multiply, and to the right to divide
- The shifts multiply or divide by two, depending on the direction
For example, to multiple 12 by two:

32 16 8 4 2 1 0 0 1 1 0 0 = 12 Shift to the left

32 16 8 4 2 1 0 1 1 0 0 0 = 24 For example, to divide 12 by two:

32 16 8 4 2 1 0 0 1 1 0 0 = 12 Shift to the right

32 16 8 4 2 1 0 0 0 1 1 0 = 6

- The shifts multiply or divide by two, depending on the direction

- Digits are shifted to the left to multiply, and to the right to divide
- An arithmetic shift is used for multiplying or dividing a signed binary number
- Apart from being used for signed numbers, they are identical to logical shifts
For example, to multiple -12 by two:

MSB 32 16 8 4 2 1 0 0 0 1 1 0 0 = 12 Convert 12 to negative

MSB 32 16 8 4 2 1 1 1 1 0 0 1 1 = -13 Add 1

MSB 32 16 8 4 2 1 1 1 1 0 1 0 0 = -12 Shift to the left

MSB 32 16 8 4 2 1 1 1 0 1 0 0 0 = -24

- Apart from being used for signed numbers, they are identical to logical shifts

- A logical shift is used for multiplying or dividing a binary number