Conversion of Number System

advertisement
Conversion of Binary, Octal and
Hexadecimal Numbers
From Binary to Octal
Starting at the binary point and working left, separate the bits into
groups of three and replace each group with the corresponding octal
digit.
100010112 = 010 001 011 = 2138
From Binary to Hexadecimal
Starting at the binary point and working left, separate the bits into
groups of four and replace each group with the corresponding
hexadecimal digit.
100010112 = 1000 1011 = 8B16
From Octal to Binary
Replace each octal digit with the corresponding 3-bit binary string.
2138 = 010 001 011 = 100010112
From Hexadecimal to Binary
Replace each hexadecimal digit with the corresponding 4-bit binary
string.
8B16 = 1000 1011 = 100010112
Conversion of Decimal Numbers
From Decimal to Binary
2 139
2 69
1
1
2
34
0
2
17
1
2
8
0
2
4
0
2
2
0
1
LSD
13910 = 100010112
MSD
From Binary to Decimal
100010112
= 1×27 + 0×26 + 0×25 + 0×24 + 1×23 + 0×22 + 1×21 + 1×20
= 128 + 8 + 2 + 1
Conversion of Fractions
Starting at the binary point, group the binary digits that lie to
the right into groups of three or four.
0.101112 = 0.101 110 = 0.568
0.101112 = 0.1011 1000 = 0.B816
Problems
Convert the following
Binary
10011010
Octal
Decimal
Hex
2705
2705
3BC
Binary
10011010
10111000101
101010010001
1110111100
Octal
232
2705
5221
1674
8 2705 1
8 338 2
8
42 2
5
Decimal
154
1477
2705
956
16 2705 1
16 169 9
10=A
Hex
9A
5C5
A91
3BC
Add
1
1
1
1
+ 1
0
0
1
+
1
0
0
0
1
1
0
0
0
1
1
1
1
1
0
0
1
1
1
0
0
1
1
1
1
1
0
0
0
0
0
1
1
0
0
1
1
1
1
1
1
1
0
0
Subtract
1
-
-
Multiply
normally
for implementation - add the shifted
multiplicands one at a time.
1
1
1
0
= 14
1
1
0
1
= 13
1
1
1
0
0
0
0
0
1
1
1
0
+ 1
1
1
0
1
1
1
0
*
0
1
1
1
1
1
0
1
1
0
1
1
1
1
0
+ 0
0
0
0
0
1
1
1
0
+ 1
1
1
0
1
0
0
0
1
1
0
+ 1
1
1
0
1
1
1
0
1
1
0
*
0
0
(8 bits)
Divide
1101
110
1111) 11000101|
1111
|
1001101|
1111
|
1101) 1011001|
1101
|
100101|
1101
|
10001|
1011|
0000
0000|
|
10001|
1111|
10
1001
1101) 1111001|
1101
|
10001|
0000
|
10001|
0000
|
10001|
1101|
100
1011
Sign-Magnitude
0 = positive
1 = negative
n bit range = -(2n-1-1) to +(2n-1-1)
4 bits range = -7 to +7
2 possible representation of zero.
2's Complement
flip bits and add one.
n bit range = -(2n-1) to +(2n-1-1)
4 bits range = -8 to +7
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111
=0
=1
=2
=7
= -8
= -7
= -2
= -1
Example
1110
0001
0010
= 14
flip bits
add one WRONG this is not -14. Out of range. Need 5 bits
0 1 1 1 0 = 14
1 0 0 0 1 flip bits
1 0 0 1 0 add one. This is -14.
Sign Extend
add 0 for positive numbers
add 1 for negative numbers
Add 2's Complement
1110
= -2
+ 1101
11011
= -3
1110
= -2
+ 0011
=3
ignore carry = -5
10001
ignore carry = 1
Be careful of overflow errors. An addition overflow occurs whenever the sign of the sum if
different from the signs of both operands. Ex.
0100
=4
1100
= -4
+ 0101
=5
+ 1011
= -5
1001
= -7 WRONG
10111
ignore carry = 7 WRONG
Multiply 2's Complement
*
1110
= -2
1101
= -3
11111110
+
+
= -2
0011
=3
11111110
0000000
+1 1 1 1 1 1 0
11111110
111111010
111110
111110110
+
sign extend to 8 bits
*
1110
00010
100000110
*
ignore carry
negate -2 for sign bit
ignore carry = 6
10010
= -14
10011
= -13
1111110010
sign extend to 10 bits
+ 111110010
11111010110
ignore carry
+ 00000000
1111010110
+ 0000000
1111010110
+ 001110
10010110110
negate -14 for sign bit
ignore carry = 182
sign extend to 8 bits
ignore carry = -6
Floating-Point Numbers
mantissa x (radix)exponent
The floating-point representation always gives us more range and less precision than the
fixed-point representation when using the SAME number of digits.
Mantissa
Sign
sign
exponent
General format
0
1
9
Mantissa 8-bit excess-127
sign
characteristic
32-bit standard
Mantissa magnitude
31
23-bit normalized fraction
Implied binary point
0
1
12
63
Mantissa
11-bit excess
52-bit normalized fraction
sign
1023 charactstic
64-bit standard
Normalized fraction - the fraction always starts with a nonzero bit. e.g.
0.01 … x 2e would be normalized to 0.1 … x 2e-1
1.01 … x 2e would be normalized to 0.101 … x 2e+1
Since the only nonzero bit is 1, it is usually omitted in all computers today. Thus, the 23-bit
normalized fraction in reality has 24 bits.
The exponent is represented in a biased form.
•
•
•
•
If we take an m-bit exponent, there are 2m possible unsigned integer values.
Re-label these numbers: 0 to 2m-1 → -2m-1 to 2m-1-1 by subtracting a constant value (or
bias) of 2m-1 (or sometimes 2m-1-1).
Ex. using m=3, the bias = 23-1 = 4. Thus the series 0,1,2,3,4,5,6,7 becomes -4,-3,-2,1,0,1,2,3. Therefore, the true exponent -4 is represented by 0 in the bias form and -3 by
+1, etc.
zero is represented by 0.0 … x 20.
Ex. if n = 1010.1111, we normalize it to 0.10101111 x 24. The true exponent is +4. Using the
32-bit standard and a bias of 2m-1-1 = 28-1-1 = 127, the true exponent (+4) is stored as a biased
exponent of 4+127 = 131, or 10000011 in binary. Thus we have
0|10000011|01011110000000000000000
Notice that the first 1 in the normalized fraction is omitted.
The biased exponent representation is also called excess n, where n is 2m-1-1 (or 2m-1).
Download
Random flashcards
Arab people

15 Cards

Radioactivity

30 Cards

Marketing

46 Cards

Ethnology

14 Cards

History of Europe

27 Cards

Create flashcards