2. NUMBERS ARE EXPRESSED IN DIFFERENT WAYS
一二三
Chinese
l ll lll
Roman
1 2 3
Hindu-Arabic
3. OUR NUMBER SYSTEM – DECIMAL OR DENARY
SYSTEM
Adopted from the Hindu-Arabic numeral system
We use ten digits:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
4. BINARY NUMBER SYSTEM
Number system based on 2
0 and 1 are used
0 = off
1 = on
As only 2 numbers are used, calculations can be performed quickly
5. DENARY NUMBER SYSTEM
We learnt numbers by dividing into columns
Each heading is multiplied by 10
100x10 10x10 1x10
Thousands Hundreds Tens Units
2 0 1 4
1 9 8 5
0 5 2 3
0 0 3 1
0 0 0 8
6. BINARY SYSTEM
Each heading is multiplied by 2
16x2 8x2 4x2 2x2 1x2 64x2 32x2
128 64 32 16 8 4 2 1
1 0 0 0 0 0 0 1
So, we have
One 128
None of the rest
And one 1
Therefore 128 + 1 = 129
7. BINARY SYSTEM
Even if the number starts with 0, we usually include it:
128 64 32 16 8 4 2 1
0 0 0 0 0 0 0 1
This has none of the numbers except one 1
So the answer is 1
But we express 1 in binary as: 00000001
8. NEGATIVE NUMBERS
So far we have only looked at positive numbers.
In 8-bit binary, there is nowhere to put a negative sign -
128 64 32 16 8 4 2 1
1 0 0 0 0 0 0 1
9. SIGN / MAGNITUDE REPRESENTATION
So we replace the first column (128) and make it stand for +/-
+/- 64 32 16 8 4 2 1
We use a 1 to stand for the negative sign(-), and 0 if it’s a positive number (+)
So -75 is
+/- 64 32 16 8 4 2 1
1 1 0 0 1 0 1 1
10. SIGN / MAGNITUDE REPRESENTATION
Imagine a line that divides the sign and the magnitude
+/- 64 32 16 8 4 2 1
SIGN
+/-
MAGNITUDE
Size of the
number
12. PROBLEMS
+/- 64 32 16 8 4 2 1
1 1 0 0 1 0 1 1
Previously, we could use all columns and make a number up to 255.
Now, the biggest number we can make is halved, because we have replaced the 128
column with +/-.
Second, the binary number contains values AND ALSO a sign.
This makes it difficult to do arithmetic.
E.g. We can’t add a – sign to 1
13. 2s Complement
2s complement allows us to represent negative numbers without having to
worry about using a sign instead of a number
In 2s complement we use -128 instead of -, which looks like this:
-128 64 32 16 8 4 2 1
14. 2s Complement
OK, se we want to represent -75 in 2s complement binary
As it’s a negative number, we need a 1 in the -128 column
-128 64 32 16 8 4 2 1
1
15. 2s Complement
BUT, -128 is 53 too many (-128 – (-75) = -53)
This means we need to add 53 to get back to -75
So, 53 is 0*64
-128 64 32 16 8 4 2 1
1 0
16. 2s Complement
BUT, -128 is 53 too many (-128 – (-75) = -53)
This means we need to add 53 to get back to -75
So, 53 is 0*64, 1*32
-128 64 32 16 8 4 2 1
1 0 1
17. 2s Complement
BUT, -128 is 53 too many (-128 – (-75) = -53)
This means we need to add 53 to get back to -75
So, 53 is 0*64, 1*32, 1*16,
-128 64 32 16 8 4 2 1
1 0 1 1
18. 2s Complement
BUT, -128 is 53 too many (-128 – (-75) = -53)
This means we need to add 53 to get back to -75
So, 53 is 0*64, 1*32, 1*16, 0*8,
-128 64 32 16 8 4 2 1
1 0 1 1 0
19. 2s Complement
BUT, -128 is 53 too many (-128 – (-75) = -53)
This means we need to add 53 to get back to -75
So, 53 is 0*64, 1*32, 1*16, 0*8, 1*4,
-128 64 32 16 8 4 2 1
1 0 1 1 0 1
20. 2s Complement
BUT, -128 is 53 too many (-128 – (-75) = -53)
This means we need to add 53 to get back to -75
So, 53 is 0*64, 1*32, 1*16, 0*8, 1*4, 0*2
-128 64 32 16 8 4 2 1
1 0 1 1 0 1 0
21. 2s Complement
BUT, -128 is 53 too many (-128 – (-75) = -53)
This means we need to add 53 to get back to -75
So, 53 is 0*64, 1*32, 1*16, 0*8, 1*4, 0*2, 1*1
-128 64 32 16 8 4 2 1
1 0 1 1 0 1 0 1
22. BINARY ADDITION
Adding two binary numbers isn’t really that scary – it’s just the same as adding
denary numbers!
You need to work from right to left, just the same
Remember that there’s only 1 and 0, adding two 1s means you need to carry 1
to the next column
24. BINARY SUBTRACTION
Subtraction can cause problems, especially when subtracting a number from a smaller number.
75 – 14 is the same as 75 + (-14)
We use 2s complement to convert the numbers
-128 64 32 16 8 4 2 1
1 0 1 1 0 1 0 1
25. OCTAL
Base of 8
We use 8 digits:
0,1,2,3,4,5,6,7
Headings become:
512 64 8 1
0 1 1 3
So, above we have
64+8+(3*1) = 75
26. BINARY CODED DECIMAL (BCD)
Each denary digit is represented separately
Four binary digits are used (nibbles):
Binary Denary
8 4 2 1
0 1 1 1 = 4+2+1 = 7
0 1 0 1 = 4+1 = 5
1 0 0 1 = 8+1 = 9
27. BINARY CODED DECIMAL (BCD)
Each denary digit is represented separately
Four binary digits are used:
Denary Binary
8 4 2 1
7 = 0 1 1 1
5 = 0 1 0 1
So, 75 in BCD is 01110101