Upload
mrlee2014
View
340
Download
0
Embed Size (px)
DESCRIPTION
Number systems, including Binary, Sign/Magnitude, 2s Complement, Binary addition, Octal and BCD
Citation preview
NUMBER SYSTEMS
NUMBERS ARE EXPRESSED IN DIFFERENT WAYS
一二三
Chinesel ll lll
Roman
1 2 3Hindu-Arabic
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
DENARY NUMBER SYSTEMWe learnt numbers by dividing into columns
Each heading is multiplied by 10
Thousands Hundreds Tens Units
2 0 1 4
1 9 8 5
0 5 2 3
0 0 3 1
0 0 0 8
1x1010x10100x10
BINARY SYSTEM
128 64 32 16 8 4 2 1
1 0 0 0 0 0 0 1
Each heading is multiplied by 2
So, we have
One 128
None of the rest
And one 1
Therefore 128 + 1 = 129
1x22x24x28x216x232x264x2
BINARY SYSTEM
128 64 32 16 8 4 2 1
0 0 0 0 0 0 0 1
Even if the number starts with 0, we usually include it:
This has none of the numbers except one 1
So the answer is 1
But we express 1 in binary as: 00000001
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
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
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
POSITIVE+/- 64 32 16 8 4 2 1
0 1 0 0 0 0 0 1
0 0 1 0 0 1 1 1
0 0 0 1 1 1 0 1
NEGATIVE+/- 64 32 16 8 4 2 1
1 1 0 0 0 0 0 1
1 0 1 0 0 1 1 1
1 0 0 1 1 1 0 1
Denary
65
39
29
Denary
-65
-39
-29
PROBLEMS
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
+/- 64 32 16 8 4 2 1
1 1 0 0 1 0 1 1
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
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
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
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
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
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
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
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
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
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
DEMO
0 0 0 1 0 0 1 0
+ 0 0 0 1 0 1 0 0
00+0=0
1
1+0=1
11+0=1
0
0+0=0
01
1+1=0(carry 1)
10+0+1=1(1 was carried over)
000+0=0
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
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
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
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