Download as pdf or txt
Download as pdf or txt
You are on page 1of 15

BCD and Binary Arithmetic Operations

CSE 1125: Digital Logic Design – Week 2


Lec Raiyan Rahman
Dept of CSE, UIU
raiyan@cse.uiu.ac.bd

7/26/2023 LEC RAIYAN RAHMAN, DEPT OF CSE, UIU 1


Binary Numbers and Binary Coding
• Given n binary digits (called bits), a binary code is a mapping from a
set of represented elements to a subset of the 2n binary numbers.
• Example: A
binary code
for the seven
colors of the
rainbow
• Code 100 is
not used

1/27/2023 Lec Raiyan Rahman, Dept. of CSE, UIU 2


Binary Numbers and Binary Coding
• Given M elements to be represented by a binary code, the minimum
number of bits, n, needed, satisfies the following relationships:

n = log2 M

Here M= 7
n = log2 M = log2 7 = 2.80

1/27/2023 Lec Raiyan Rahman, Dept. of CSE, UIU 3


Binary Numbers and Binary Coding
• Suppose you are using n number of digits, in radix r, there are
maximum of rn distinct elements that can be represented.
• Examples:
• You can represent 4 elements in radix r = 2 with n = 2 digits: (00, 01, 10, 11).
• You can also represent 4 elements in radix r = 2 with n = 4 digits: (0001, 0010,
0100, 1000).

1/27/2023 Lec Raiyan Rahman, Dept. of CSE, UIU 4


Lecture Outline
Binary arithmetic
A Brief History of Numbers and Civilizations
• Binary Addition
How can we understand the numbers of other
civilizations ? • Binary Subtraction
• Binary to decimal • Binary Multiplication
• Octal to decimal • Binary Division
• Hexadecimal to decimal
• Complements
What our numbers can mean to other civilizations
• Decimal to binary
Representation using binary
• Decimal to octal numbers
• Decimal to hexadecimal
Binary Codes
Conversion of number systems with 2n digits
Binary Coded Decimal (BCD)
• Octal ↔ Binary
BCD Addition
• Hexadecimal ↔ Binary
• Octal ↔ Hexadecimal
10/1/2023 Lec Raiyan Rahman, Dept. of CSE, UIU 5
Lecture Outline
Binary arithmetic
A Brief History of Numbers and Civilizations
• Binary Addition
How can we understand the numbers of other
civilizations ? • Binary Subtraction
• Binary to decimal • Binary Multiplication
• Octal to decimal • Binary Division
• Hexadecimal to decimal
• Complements
What our numbers can mean to other civilizations
• Decimal to binary
Representation using binary
• Decimal to octal numbers
• Decimal to hexadecimal
Binary Codes
Conversion of number systems with 2n digits
Binary Coded Decimal (BCD)
• Octal ↔ Binary
BCD Addition
• Hexadecimal ↔ Binary
• Octal ↔ Hexadecimal
10/1/2023 Lec Raiyan Rahman, Dept. of CSE, UIU 6
Binary Addition

0+0=0 carry=0 Add the Add the


following: following:
1+0 =1 carry=0
10001 10111
0+1=1 carry =0
(+) 1 1 1 0 1 (+) 1 1 0 0 0 1
1+1=0 carry=1
———————– ———————–

10/1/2023 Lec Raiyan Rahman, Dept. of CSE, UIU 7


Binary Subtraction

Binary
Subtraction Value
Number

0–0 0

1–0 1

1 (Borrow 1 from the next high order


0–1
digit)

1–1 0

10/1/2023 Lec Raiyan Rahman, Dept. of CSE, UIU 8


Binary Subtraction

Binary Subtraction Number

0–0
Value

1–0 1

Subtract : Subtract : 0–1 1 (Borrow)

11011 1110 1–1 0

(-) 1 0 1 1 0 (-) 111


———————– ———————–

Hint: Borrow 2 from the nearest 1 to the left

10/1/2023 Lec Raiyan Rahman, Dept. of CSE, UIU 9


Binary Multiplication

•0×0=0
•0×1=0
•1×0=0
•1×1=1

10/1/2023 Lec Raiyan Rahman, Dept. of CSE, UIU 10


Binary Multiplication

•0×0=0
•0×1=0
•1×0=0
•1×1=1

10/1/2023 Lec Raiyan Rahman, Dept. of CSE, UIU 11


Binary Division

10/1/2023 Lec Raiyan Rahman, Dept. of CSE, UIU 12


Binary Division

10/1/2023 Lec Raiyan Rahman, Dept. of CSE, UIU 13


Binary Division
• Let us divide 128 by 8
• Let us divide 101010 by 110
• Now divide 26 by 5
• Do the same , but in binary : 11010 divided by 101

10/1/2023 Lec Raiyan Rahman, Dept. of CSE, UIU 14


Thank You

1/27/2023 Lec Raiyan Rahman, Dept. of CSE, UIU 15

You might also like