CH 2
CH 2
Numbering Systems
1
2.1 Decimal Number
The decimal numbering system has 10 digits 0 through 9
….105 104 103 102 101 100. 10-110-2 10-3 10-4 10-5…
Example :
Express decimal 47 as a sum of the values of each digit :
47 = (4 x 101) + (7 x 100)
= 40 + 7
= 47
2
2.2 Binary Number
• The binary numbering system has 2 digits 0 and 1
increase increase
• Example :
101112 = (1 X 24 + 0 X 23 + 1 X 22 + 1 X 21 + 1 X 20 )
3
24 23 22 21 20
1 0 1 1 1
1x16 0x8 1x4 1x2 1x1
16 0 4 2 1
16 + 4 + 2 + 1 = 2310
4
2.3 a) Binary-to-Decimal Conversion
• Convert binary to decimal by summing the positions that
contain a 1
1 0 0 1 0 12
5
Binary Count
6
Binary-to-Decimal Conversion
1 0 0 1 0 1
Step 3:
multiply 25 24 23 22 21 20
= 32 0 0 4 0 1
Step 4:
sum +
37
25 24 23 22 21 20
32 16 8 4 2 1
8
2.3 b) Decimal-to-Binary Conversion
9
1) Sum-of-weight method
Binary weights
128 64 32 16 8 4 2 1
357 = 256 + 64 + 32 + 4 + 1 101100101
= 28 + 26 + 25 + 22 + 20
Binary weights
512 256 128 64 32 16 8 4 2 1
1937 = 1024 + 512 + 256 + 128 + 16 + 1 11110010001
10
1) Sum-of-weight method
Nearest weight to 58 58
minus
32 32 16 8 2
26 Apply a 1 to these
minus
weights and 0 to others
16
10
minus
8
2
minus
2 25 24 23 22 21 20
0 32 16 8 4 2 1
5810 = 1110102
1 1 1 0 1 0
11
1) Sum-of-weight method
82
minus
64 64 16 2
18 Apply a 1 to these
minus
weights and 0 to others
16
2
minus
2
0
26 25 24 23 22 21 20
64 32 16 8 4 2 1
1 0 1 0 0 1 0
12
1) Sum-of-weight method
• Try this for 25 and 125
125
minus
25 64
minus 64 32 16 8 4 1
16 16 8 1 61 Apply a 1 to these
minus
weights and 0 to others
9 Apply a 1 to these 32
minus
weights and 0 to others
8 29
minus
1 16
minus
1 13
minus 26 25 24 23 22 21 20
0 8
5 64 32 16 8 4 2 1
24 23 22 21 20 minus
4 1 1 1 1 1 0 1
16 8 4 2 1
1
1 1 0 0 1 minus
1
0
13
2)Repeated division-by-2
• Repeated division steps:
– Divide the decimal number by 2
– Write the remainder after each division until a
quotient of zero is obtained.
– The first remainder is the LSB and the last is
the MSB
• Note, when done on a calculator, a
fractional answer indicates a remainder of 1.
14
• This flowchart describes the
process and can be used to
convert from decimal to any
other number system.
15
1210 = X2 Remainder
12 = 6 0
Right/LSB
6 = 3 0
2 1 1 0 0
3 = 1 1
2
1 = 0 1
2 Left/MSB
45 = 22 1
Right/LSB
2
22 = 11 0
2
11 = 5 1 0 1 1 0 1
1
2
5 = 2 1
2
2 = 1 0
2
1 = 0 1 17
2 Left/MSB
Converting Decimal Fractions-to-Binary
• 2 ways to convert:
– 1) Sum-of-weight
– 2) Repeated multiplication of 2
2 -1 2 -2 2 -3 2 -4
divide by 2 from
previous value
18
2) Repeated multiplication by 2
• Conversion of decimal-binary
– Whole numbers repeated division by 2
– Fractions repeated multiplication by 2
Step 1: multiply number by 2
Step 2: note the carry (1 or 0)
Step 3: repeat with new fraction
Stop when fraction part = 0
19
carry
left/MSB
0.3125 x 2 = 0.625 0
0.625 x 2 = 1.25 1
. 0 1 0 1
0.25 x 2 = 0.50 0
0.50 x 2 = 1.00 1
right/LSB
21
2.5 Hexadecimal Number
System
• Most digital systems deal with groups of bits in
even powers of 2 such as 8, 16, 32, and 64 bits.
• Hexadecimal uses groups of 4 bits.
• Base 16
– 16 possible symbols
– 0-9 and A-F
• Allows for convenient handling of long binary
strings.
22
Hex-to-Decimal Conversion
• Convert from hex to decimal by multiplying
each hex digit by its positional weight.
• Example:
1 256 6 16 3 1
35510
Decimal-to-Hex Conversion
• Convert from decimal to hex by using the
repeated division method used for decimal to
binary and decimal to octal conversion.
650 Right/LSB
= 40.625 x 16 = 10 = A
16
40 2 8 A
= 2.5 x 16 = 8
16
2
= 0.125 x 16 = 2
16
Left/M SB
done!
650 10 = 28A 16
25
Binary-to-Hex Conversion
26
Example
Decimal 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Hexadecimal 0 1 2 3 4 5 6 7 8 9 A B C D E F
Binary 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
1100101001010111 2
1100101001010111 2
12 10 5 7
C A 5 7
C A 57 16
28
Hex-to-Binary
• Represent each hex decimal digit to binary.
• Concatenate the result.
29
Example
Decimal 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Hexadecimal 0 1 2 3 4 5 6 7 8 9 A B C D E F
Binary 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
9F216 = 9 F 2
= 1001 1111 0010
= 1001111100102
30
Hex and Octal
31
2.6 Octal Number
• The Octal Number System:
– uses base 8
– includes only the digits 0 through 7
85 84 83 82 81 80
32768 4096 512 64 8 1
32
2.6 Octal Number
Binary-to-Octal Conversion
(ex : 10101111101100102)
1 2 7 6 6 2
001 010 111 110 110 010
33
2.7 Binary Arithmetic
Addition
Subtraction
Multiplication
Division
Complement
34
Binary Addition
Binary Addition works like “normal” addition
Stay with in {0,1}
Carries as usual
Example
Carry: 1 1 1 1 1 1
1 1 1 1 0 1
+ 1 0 1 1 1
1 0 1 0 1 0 0
Addition of multiple numbers possible
Carry gets a bit more difficult
35
Binary Subtraction
Subtraction same as “normal” subtraction
Borrows as usual
Example:
1 1 1 1 0 1
- 1 0 1 1 1
1 0 0 1 1 0
36
Binary Multiplication
Same as “normal” multiplication
Multiplication a lot easier in binary domain
Example:
1 1 1 1 0 1
x 1 0 1 0
0 0 0 0 0 0
1 1 1 1 0 1
0 0 0 0 0 0
1 1 1 1 0 1
1 0 0 1 1 0 0 0 1 0
37
Binary Division
Same as “normal” division
Example:
38
Complement
1’s complement
2’s complement
39
1’s complement
• The 1’s complement of binary number is
found by all 1s to 0s and all 0s to 1s
42
Example: Express -45 in 8-bit 2’s complement form.
Solution
+45 in 8-bit form is 00101101.
First method
Obtain the 1’s complement of 00101101 and then add 1.
Positive expression of the given number 00101101
1’s complement of it 11010010
Add 1 +1
Thus, the 2’s complement form of -45 is 11010011
Second method
Subtract the given number N from 2n
2n = 100000000
Subtract 45 = 00101101
Thus, the 2’s complement form of -45 is 11010011
Third method
Copy down the bits starting from LSB up to and including the first 1, and
then complement the remaining bits.
Original number 00101101
Copy up to first 1 bit 1
Complement the remaining bits 1101001
Thus, the 2’s complement form of -45 is 11010011 43
2.8 Signed Numbers
Digital systems, such as the computer, must be able to
handle both positive and negative numbers.
A signed binary number consists of both sign and
magnitude information.
The sign indicates whether a number is positive or
negative and the magnitude is the value of the number.
There are three forms in which signed integer (whole)
numbers can be represented in binary:
Sign-magnitude,
1's complement, and
2's complement.
Of these, the 2's complement is the most important and
the sign-magnitude is rarely used.
44
The Sign Bit
The left-most bit in a signed binary number is the sign
bit, which tells you whether the number is positive or
negative.
a 0 is for positive, and
a 1 is for negative
45
Sign-Magnitude Form
When a signed binary number is represented in sign-
magnitude, the left-most bit is the sign bit and the remaining
bits are the magnitude bits.
The magnitude bits are in true (uncomplemented) binary for
both positive and negative numbers.
For example, the decimal number +25 is expressed as an 8-bit
signed binary number using the sign-magnitude form as:
00011001
47
2’s Complement Form
Negative numbers are the 2’s complements
of the corresponding positive numbers
48
2.9 Signed Numbers-to-Decimal
Sign-magnitude
Sum the weights of all magnitude bit positions
The sign is determined by the examination of the
sign bit
1’s complement
Assign a negative value to the weight of the sign bit
Sum all the weights where there are 1s
Add 1 to the result(if the number is negative)
2’s complement
Assign a negative value to the weight of the sign bit
Sum all the weights where there are 1s 49
Examples
Sign-magnitude
1’s complement
2’s complement
50
2’s Complement Arithmetic
The 2's complement system is used to represent negative
numbers using modulus arithmetic.
The word length of a computer is fixed.
That means if a 4-bit number is added to another 4-bit
number, the result will be only of 4 bits. Carry, if any, from
the fourth bit will overflow.
This is called the modulus arithmetic.
For example: 1100 + 1111 = 1011.
In the 2's complement subtraction, add the 2's complement
of the subtrahend to the minuend.
If there is a carry out, ignore it. Look at the sign bit, i.e. MSB
of the sum term.
If the MSB is a 0, the result is positive and is in true binary
form.
If the MSB is a 1 (whether there is a carry or no carry at all)
the result is negative and is in its 2's complement form.
Take its 2's complement to find its magnitude in binary. 51
Cont…
Example: subtract 14 from 46 using the 8-bit 2’s
complement arithmetic.
Solution
+14 = 00001110
14 = 11110010 (in 2’s complement form)
+46 00101110
14 +11110010 (2’s complement form of14)
+32 100100000 (Ignore the carry)
There is a carry, ignore it.
The MSB is 0; so, the result is positive and is in
normal binary form.
Therefore, the result is +00100000=+32 52
Cont…
Example: add 75 to +26 using the 8-bit 2’s
complement arithmetic
Solution
+75 = 01001011
75 = 10110101 (in 2’s complement form)
+26 00011010
75 +10110101 (2’s complement form of -75)
49 11001111 (No carry)
There is no carry, the MSB is a 1.
So, the result is negative and is in 2’s complement
form.
The magnitude is 2’s complement of 11001111, that
is, 00110001=49.
Therefore, the result is 49. 53
1’s Complement Arithmetic
The 1's complement of a number is obtained by simply
complementing each bit of the number, that is, by changing all
the 0s to 1 s and all the 1 s to 0s.
We can also say that the 1's complement of a number is obtained
by subtracting each bit of the number from l.
This complemented value represents the negative of the original
number.
This system is very easy to implement in hardware by simply
feeding all bits through inverters.
One of the difficulties of using 1's complement is its
representation of zero.
Both 00000000 and its 1's complement 11111111 represent zero.
The 00000000 is called positive zero and the 11111111 is called
negative zero.
In 1's complement subtraction, add the 1's complement of the
subtrahend to the minuend.
If there is a carry out, bring the carry around and add it to the
LSB. This is called the end around carry. 54
Cont…
Example: subtract 14 from 25 using the 8-bit 1’s
complement arithmetic
Solution
+25 00011001
14 +11110001 (1’s complement form of 14)
+11 100001010
+1 (Add the end around carry)
00001011 =+ 1110
55
Cont…
Example: Add 25 to 14 using the 8-bit 1’s
complement method.
Solution
+14 00001110
25 +11100110 (1’s complement form of
25)
11 11110100 (No carry)
There is no carry, the MSB is a 1.
So, the result is negative and is in its 1’s
complement form.
The 1’s complement of 11110100 is 00001011.
The result is, therefore, 1110. 56
Cont…
The two numbers in addition are the addend
and the augend. The result is the sum. The 2’s
compliment will be used to represent negative
numbers.
There are four cases that must be considered
when adding two numbers:
57
Cont…
1. Both numbers positive:
In this case, both sign bits are zero and a 2's compliment
is not required. To illustrate, we will add +7 and +4:
7 00000111
4 00000100
11 00001011
2. Positive number and smaller negative number:
In this case, the true binary form of the positive number is
added to the 2's complement of the negative number.
The sign bits are included in the addition, and the result
will be positive. To illustrate we will add + 15 and -6:
15 00001111
+ -6 11111010
9 100001001
Discard carry
Notice that the sign of the sum is positive (0) as it should be.58
Cont…
3. Positive number and larger negative number:
Again, the true binary form of positive number is added
to the 2's complement of the negative number.
The sign bits are included in the addition, and the result
will be negative. To illustrate will add + 16 and - 24:
16 00010000
+ -24 11101000 (2’s complement of -24)
-8 11111000 (2’s complement of -8)
Notice that the result automatically comes out in 2's
complement because it is a negative number.
4. Both numbers negative:
In this case, the 2's complements of both numbers added
and, of course, the sum is a negative number in 2's
complement form illustrate, we will add - 5 and -9:
-5 11111011 (2’s complement of -5)
+ -9 11110111 (2’s complement of -9)
-14 111110010 (2’s complement of -14) 59
Discard carry
Overflow
When the number of bits in the sum exceeds the number of
bits in each of numbers added, overflow results, as
illustrated by the following example.
0000 0001 0010 0011 0100 0101 0110 0111 1000 1001
61
2.11 Digital Codes and Parity
62
Gray-to- Binary Code
is not an arithmetic code
Only one bit changes from one code to the next in the
sequence
Gray code can be any amounts of bits.
Below is example from Gray Code-to-Binary
Eg : 1110 (Gray Code)
1 1 1 0
+ + +
1 0 1 1
= 10112
63
Binary-to- Gray Code
Below is example from Binary-to-Gray Code
Eg : 11102
1 + 1 + 1 + 0
1 0 0 1
64
DECIMAL BINARY GRAY CODE
0 0000 0000
1 0001 0001
2 0010 0011
3 0011 0010
4 0100 0110
5 0101 0111
6 0110 0101
7 0111 0100
8 1000 1100
9 1001 1101
10 1010 1111
11 1011 1110
12 1100 1010
13 1101 1011
14 1110 1001
15 1111 1000 65
ASCII
American Standard Code for Information
Interchange (ASCII)
It has 128 characters and symbols
represented in 7-bit binary code
Example :
A = 10000012;
a = 11000012
66
Kos ASCII : 10000012
ASCII Table
000 001 010 011 100 101 110 111
67
Symbol Binary Hexadecimal
2 0110010 32
ASCII example: 0
Space
0110000
0100000
30
20
P 1010000 50
20 PRINT A=“X”; R 1010010 52
I 1001001 49
N 1001110 4E
T 1010100 54
Space 0100000 20
A 1000001 41
= 0111101 3D
10000012 = 0100 00012 “ 0100010 22
4 116 X 1011000 3B
“ 0100010 22
; 0111011 3B
68
Parity
• Parity bit used for bit error detection
– Even parity (0) – total number of 1s even
– Odd parity (1) – total number of 1s odd
• Example: (even parity)
69
EVEN PARITY ODD PARITY
1 0111 0 0111
1 1000 0 1000
0 1001 1 1001
70
Try this. Fill in the appropriate parity bit.
Even Odd
1010 0 1
111000 1 0
101101 0 1
1000111001001 0 1
101101011111 1 0
71
THE END
72