09 CALD Lec 09 Binary Codes, Gray Code
09 CALD Lec 09 Binary Codes, Gray Code
Codes
BESE-13AB, Spring 2023
Dated 27 February, 2023
By Nasir Mahmood
[email protected]
[email protected]
1
Example Arithmetic (Signed 2’s Complement)
Arithmetic 9 and 11
2
Arithmetic Subtraction
3
Example
4
Binary Codes
● All symbols in a computer must be represented by a
binary code (binary representation).
5
BCD Code (8 4 2 1)
6
Multi-Digit BCD
7
BCD Addition
● BCD only represents each of the decimal digitals 0 through
9 as a single 4-bit binary value.
● When adding two BCD values, if the sum is equal to or less
than 1001 (9), the corresponding BCD value is correct.
● However, when the binary sum is greater or equal to 1010
(10), the result is an invalid BCD value.
● To overcome the invalid BCD value add 0110 (6) to the result to obtain the
BCD representation and also produces a carry as required.
● The use of 0110 (6) works because the difference between a carry in the
most significant bit position of the binary sum and a decimal carry differ
by 16-10 = 6.
8
BCD Addition Examples
9
Multi-Digit BCD Addition
Add 295 and 635 in BCD
10
BCD Arithmetic
● BCD arithmetic involving negative numbers uses the 10’s complement for
representing the negative numbers including the sign digit.
● 0 (0000) represents a positive sign and 9 (1001) represents a negative sign
● Note: To obtain 10’s complement of a BCD number, we first take the 9’s complement (by
subtraction of each digit from 9) and then add one to least significant digit
11
D
End of Lecture
12