Logic Design 3
Logic Design 3
YOUSRA AHMED
Lec_3
Binary Arithmetic
Binary arithmetic includes the basic arithmetic operations of addition, subtraction,
multiplication and division. The following sections present the rules that apply to these
operations when they are performed on binary numbers.
Binary Addition
Binary addition is performed in the same way as addition in the decimal-system and is, in
fact, much easier to master. Binary addition obeys the following four basic rules
0+ 0+ 1+ 1+
0 1 0 1
0 1 1 10
The results of the last rule may seem somewhat strange, remember that these are binary
numbers. Put into words, the last rule states that.
Example
01 + 10 +
10 00
11 10
Example
111 + 1010
101 1001
1100 1101
100000
C++ 1
Logic Design Dr. YOUSRA AHMED
Lec_3
Binary Subtraction:
Binary subtraction is just as simple as addition subtraction of one bit from another according
the following four basic rules.
0–0=0
1 – 1 =0
1–0=1
0 – 1 = 1 with a transfer (borrow) of 1.
Example:
1001 -
101
100
10 0 0 0 -
0 0 101
100 11
Binary Multiplication
0*0=0
1 * 0=0
0 * 1= 1
1*1=1
C++ 2
Logic Design Dr. YOUSRA AHMED
Lec_3
Example
101 *
10
000
101
1 0 1 0
Example:
1100 *
1010
0000
1100
0000
1100
111 1 0 0 0
C++ 3
Logic Design Dr. YOUSRA AHMED
Lec_3
Binary Division
0/ 1= 0
1 / 1= 1
Example:
Example:
C++ 4
Logic Design Dr. YOUSRA AHMED
Lec_3
Coding System
Binary Coded Desimal (BCD)
ASCII CODE
Decimal: 0 1 2 3 4 5 6 7 8 9
BCD: 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001
C++ 5
Logic Design Dr. YOUSRA AHMED
Lec_3
C++ 6
Logic Design Dr. YOUSRA AHMED
Lec_3
The binary-coded decimal scheme described in this article is the most common encoding, but
there are many others. The method here can be referred to as Simple Binary-Coded Decimal
(SBCD) or BCD 8421. In the headers to the table, the '8 4 2 1' indicates the four bit weights;
note that in the 5th column two of the weights are negative. The following table represents
decimal digits from 0 to 9 in various BCD systems:
C++ 7
Logic Design Dr. YOUSRA AHMED
Lec_3
Gray Code
A Gray Code represents numbers using a binary encoding scheme that groups a sequence of
bits so that only one bit in the group changes from the number before and after. It is named for
Bell Labs researcher Frank Gray, who described it in his 1947 patent submittal on Pulse Code
Communication. A Gray Code is not weighted, the columns of bits do not reflect an implicit
base weight as the Binary number system does.
A comparison of the first ten numbers in Decimal, Binary and Gray Code is shown in Table 1.
Table 1. Decimal, Binary, Gray Code Numbers
C++ 8
Logic Design Dr. YOUSRA AHMED
Lec_3
From the above operation, finally we can get the binary values like
b3 = g3,
b2 = b3 XOR g2,
b1= b2 XOR g1,
b0 = b1 XOR g0.
C++ 9
Logic Design Dr. YOUSRA AHMED
Lec_3
From the above operation, finally we can get the binary values like
g3=b3
g2 = b3 XOR b2,
g1= b2 XOR b1,
g0 = b1 XOR b0.
C++ 11