Lecture1B. Number System, Operation, and Codes
Lecture1B. Number System, Operation, and Codes
Number systems
Binary Arithmetic Operations
Binary Codes
Number system
Decimal Numbers
Binary Numbers
Binary-to-Decimal Conversion
Decimal-to-Binary Conversion
Hexadecimal Numbers and relation with Binary
Octal Numbers and relation with Binary
Conversion between Hexadecimal, Octal, and Decimal
Number system
Decimal Numbers
A decimal number can be expressed a sum of the values of
each digit.
= 5 102 + 6 101 + 8 100 + 2 10-1 +3
(568.23)10
10-2
weight weight weight ● weight weight
The weight of a digit is a power of 10
Point
corresponding to the digit’s position.
For whole numbers, the weights are positive powers of 10, and
it increase from right to left.
For fractional numbers, the weights are negative powers of 10,
and it decreases from left to right.
Number system
Decimal Numbers
In general, a decimal number D of the form d2d1d0.d-1d-2
has the value: ( 0 di 9 )
(D)10 = d2·102 + d1·101 + d0·100 + d-1·10-1 + d-2·10-2
10 base or radix of the number system
Base-r Number system
(N) r = Kn·rn + Kn-1·rn-1 + … +K1·r1 + K0·r0 + K-1·r-1 + … +K-m·r-m
r base ri weight Ki coefficient
Number system
Base-r Number system
(N) r = Kn·rn + Kn-1·rn-1 + … +K1·r1 + K0·r0 + K-1·r-1 + … +K-m·r-m
r base (cơ ri weight Ki coefficient
số ) (trọng số) (hệ số)
Usually, r 2
m and n are positive integers
The digits or symbols of Ki are different
in different number systems
In decimal system r = 10 Ki = 0, 1, …, 9
The decimal system with its ten digits is
Number system
a base-10 system; the binary system with
Binary Numbers its two digits is base-2 system.
(N) r = Kn·rn + Kn-1·rn-1 + … +K1·r1 + K0·r0 + K-1·r-1 + … +K-m·r-m
Decimal-to-Binary Conversion
2. Repeated Division-by-2 for wholes and/or Multiplication-
by-2 for fractions Method
Example : (81.65)10 = (?)2 Quotient
2 2 2 2 2 2 2
0 1 2 5 10 20 40 81
Until the
quotient Remainder
is zero
1 0 1 0 0 0 1
K6 K5 K4 K3 K2 K1 K0
( MSB ) ( LSB )
The whole binary result is composed of remainders
Number system Until the fractional product
is zero or the limited digits
Decimal-to-Binary Conversion is reached.
2. Repeated Division-by-2 for wholes and/or Multiplication-
by-2 for fractions Method
Example : (81.65)10 = (?)2 ( Precision limited to five
bits in fractional part)
Fractional product
2 2 2 2 2 2
0.65 0.3 0.6 0.2 0.4 0.8
1 0 1 0 10 carry 1
The carry K-1 K-2 K-3 K-4 K-5 K-6
to integer
Number system
Decimal-to-Binary Conversion
2. Repeated Division-by-2 for wholes and/or Multiplication-
by-2 for fractional Method
Example : (81.65)10 = (?)2 =(1010001.10101)2
2 2 2 2 2 2
0.65 0.3 0.6 0.2 0.4 0.8
1 0 1 0 10 1
K-1 K-2 K-3 K-4 K-5 K-6
The fractional binary result is composed of carries
So : (0.65)10=(0.10101)2 (81)10 = (1010001)2
Number system
Hexadecimal Numbers and Relation with Binary
Base-16 system
(N) r = Kn·rn + Kn-1·rn-1 + … +K1·r1 + K0·r0 + K-1·r-1 + … +K-m·r-m
Here, r = 16
Hexadecimal numbers has sixteen coefficients, ten
numeric digits and six alphabetic characters
Ki = 0, 1, 2, …, 9, A, B, C, D, E, F
ten six
Number system
Hexadecimal Numbers and Relation with Binary
Base-16 system
(N)16 = Kn·16n + … +K1·161 + K0·160 + K-1·16-1 + … +K-m·16-m
= (Kn … K1 K0 . K-1 K-m)16
Division( or Multiplication)-by-2
Decimal Binary
Sum-of-Weights
Octal
D B H O
Number system 0 0000 0 0
1 0001 1 1
Brief Summary Relation 2 0010 2 2
3 0011 3 3
between several number 4 0100 4 4
systems 5 0101 5 5
6 0110 6 6
7 0111 7 7
To four bits binary number, 8 1000 8 10
the relation between them is 9 1001 9 11
10 1010 A 12
shown in this table 11 1011 B 13
12 1100 C 14
13 1101 D 15
14 1110 E 16
15 1111 F 17
Number system, Operation, and Codes
Number system
Binary Arithmetic
Binary Codes
Binary Arithmetic
Binary Arithmetic
Addition Multiplication
Subtraction Division
=-58
Binary Arithmetic Operation in Logic Device
Signed Numbers
Example: Determine the decimal values of the following signed
binary numbers expressed in 2’s complement
(a) 01000110 (b) 11000110 (c) 11000111
Another method: directly calculate the sum-of-weights
Solution: (b) 11000110 = -27 +26 +22 +21
= -128 +64 +4 +2
The weight of sign bit is negative
= -58
If the sign bit is 0, ignoring its value
Binary Arithmetic Operation in Logic Device
Arithmetic Operation with Signed Numbers
(Only discussing the whole binary numbers represented by 2’s complement form)
Addition
Add the two numbers and discard any final carry bit
Example Find the result of the sign numbers:
Sign bit 10011001+00100001 11011001+10110001
10011001 (augend) 11011001
+ 00100001 (addend) Discard final + 10110001
carry 1 10001010
10111010 (sum)
-70 (equivalent decimal) -118
Binary Arithmetic Operation in Logic Device
Addition with Signed Numbers
A danger of overflow Avoid it by extending magnitude bits
Condition: The sum exceeds the range that can be represented
by the appointed magnitude bits
Example 10011001+10110001
For seven magnitude bits
10011001 -103
Max: 01111111 +127
Discard final + 10110001 + -79
carry Min : 10000000 -128
1 01001010 -182
Out of range
Sign bit +74
Both sign and magnitude are incorrect due to overflow
How to solve this problem ?
Binary Arithmetic Operation in Logic Device
Arithmetic Operation with Signed Numbers
Subtraction
Take the 2’s complement of the subtrahend (include sign
bit) and add, moreover discard any final carry bit
Example 11011001-10110001 10011001-00100001
-39 -(-79)=+40
11011001 (Minuend)
+ 01001111 (2’s complement of subtrahend)
Discard final carry
1 00101000 (Difference)
+40 (equivalent decimal)
Binary Arithmetic Operation in Logic Device
Arithmetic Operation with Signed Numbers
Subtraction
Take the 2’s complement of the subtrahend (include sign
bit) and add, moreover discard any final carry bit
Example 11011001-10110001 10011001-00100001
-39 -(-79)=+40 -103 -33 = -136
10011001
+ 11011111
1 01111000
+120
The result is incorrect due to overflow
Binary Arithmetic Operation in Logic Device
Arithmetic Operation with Signed Numbers
Multiplication and division with Signed Numbers
Number system
Binary Arithmetic
Binary Codes
Binary Codes
150
Binary Codes
The Excess-3 code Decimal
digit
Excess-3
code
0000
It is another type of BCD code. 0001
0010
It is unweighted code. 0 0011
1 0100
There are also six invalid codes 2 0101
3 0110
(0000, 0001, 0010, 1101, 1110, 4 0 1 1 1 Invalid
1111) in Excess-3 code 5 1 0 0 0 codes
6 1001
7 1010
8 1011
9 1100
1101
1110
1111
Binary Codes
The Gray code Decimal Binary
4-bit Gray
code
It is unweighted code and is not 0 0000 0000
1 0001 0001
arithmetic code. 2 0010 0011
There is only a single bit difference 3 0011 0010
4 0100 0110
between the adjacent Gray codes. 5 0101 0111
6 0110 0101
Like binary numbers, the Gray code 7 0111 0100
8 1000 1100
can have any number of bits. 9 1001 1101
It usually represent some sequence 10 1010 1111
11 1011 1110
information 12 1100 1010
Conversion between binary and 13 1101 1011
14 1110 1001
Gray code conveniently (refer to 15 1111 1000
textbook page 77)
Binary Codes
Excess 4-bit
Dec Binary BCD
The relationship between 0 0000 0000
-3
0011
Gray
0000
several typical codes 1
2
0001
0010
0001
0010
0100
0101
0001
0011
3 0011 0011 0110 0010
Note: 4 0100 0100 0111 0110
5 0101 0101 1000 0111
“xxxx” represents “don’t care” 6 0110 0110 1001 0101
7 0111 0111 1010 0100
terms. It means these states are 8 1000 1000 1011 1100
invalid or never occur. 9 1001 1001 1100 1101
10 1010 xxxx xxxx 1111
11 1011 xxxx xxxx 1110
12 1100 xxxx xxxx 1010
13 1101 xxxx xxxx 1011
14 1110 xxxx xxxx 1001
15 1111 xxxx xxxx 1000
Binary Codes
ASCII Code
(American Standard Code for Information Interchange)
{end}