Binary and data representation - EdexcelBinary shifts and negative numbers
All data in a computer is represented in binary, whether it is numbers, text, images or sound. The computer software processes the data according to its content.
There are two different types of binary shift which work differently for negative numbers. The two types are:
arithmetic
logical
Arithmetic shift left
To multiply a negative number, an arithmetic binary 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
Result: shifting one place to the left gives 00111000 (-128 + 32 + 16 = denary -80)
128
64
32
16
8
4
2
1
1
0
1
1
0
0
0
0
128
1
64
0
32
1
16
1
8
0
4
0
2
0
1
0
Arithmetic shift right
To divide a negative 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:
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