Data representation - EduqasArithmetic shift

Binary data can represent numbers, graphics, sound and characters. It is then organised and manipulated differently. Data can also be stored in arrays, records or external files and go through validation or verification checks to ensure accuracy.

Part ofComputer ScienceUnderstanding Computer Science

Arithmetic shift

numbers are multiplied and divided using arithmetic shifts, also known as binary shifts.

Multiplying and dividing binary numbers using arithmetic shifts, also known as binary shifts

Multiplication

To multiply a number, an arithmetic shift moves all the digits in the binary number along to the left and fills the gaps after the shift with 0:

  • to multiply by two, all digits shift one place to the left
  • to multiply by four, all digits shift two places to the left
  • to multiply by eight, all digits shift three places to the left
  • and so on

Example – calculate 00001100 (denary 12) × 2

Place value1286432168421
Value1100
Place valueValue
128
64
32
16
81
41
20
10

Result: shifting one place to the left gives 00011000 (denary 24)

Place value1286432168421
Value11000
Place valueValue
128
64
32
161
81
40
20
10

Example: 00010110 (denary 22) × 4

Place value1286432168421
Value10110
Place valueValue
128
64
32
161
80
41
21
10

Result: shifting two places to the left gives 1011000 (denary 88)

Place value1286432168421
Value1011000
Place valueValue
128
641
320
161
81
40
20
10

Remember that shifting outside of the available heading values may result in an overflow error.

Division

To divide a number, an arithmetic shift moves all the digits in the binary number along to the right:

  • to divide by two, all digits shift one place to the right
  • to divide by four, all digits shift two places to the right
  • to divide by eight, all digits shift three places to the right
  • and so on

Example: 100100 (denary 36) ÷ 2

Place value1286432168421
Value100100
Place valueValue
128
64
321
160
80
41
20
10

Result: shifting one place to the right gives 10010 (denary 18)

Place value1286432168421
Value10010
Place valueValue
128
64
32
161
80
40
21
10

Example: 1111 (denary 15) ÷ 2

Place value1286432168421
Value1111
Place valueValue
128
64
32
16
81
41
21
11

Result: shifting two places to the right gives 111 (denary 7). Note - 15 ÷ 2 = 7.5. However, in this form of binary, there are no decimals, and so the decimal is discarded.

Place value1286432168421
Value111
Place valueValue
128
64
32
16
8
41
21
11

Example: 110110 (denary 54) ÷ 4

Place value1286432168421
Value110110
Place valueValue
128
64
321
161
80
41
21
10

Result: shifting two places to the right gives 1101 (denary 13)

Place value1286432168421
Value1101
Place valueValue
128
64
32
16
81
41
20
11

Negative numbers and binary shifts

There are two different types of binary shift which work differently for negative numbers: arithmetic and logical.

Arithmetic shifts

To divide a number, an arithmetic binary shift moves all the digits in the binary number along to the right and fills the gaps after the shift with the previous MSB value.

Two’s complement is better for arithmetic shifts left since the sign is always retained.

Logical shifts

In logical shifts - left or right - a 0 is always copied in. This means that a logical shift is ideal for unsigned binary numbers.