0% found this document useful (0 votes)
5 views

DLD 01 Introduction

Uploaded by

fouziajahan106
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

DLD 01 Introduction

Uploaded by

fouziajahan106
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 34

CSE 1325: Digital Logic Design

Introduction
Riasat Azim
United International University
Outline of this lecture

U • Base conversions
Decimal ↔ Binary
I

– Any base → Decimal

U – Octal ↔ Binary
– Hexadecimal ↔ Binary
• Binary Codes
• Binary Coded Decimal (BCD)
• Binary arithmetic
– Single Bit Addition with Carry
– Multiple Bit Addition
Aug 3, 2024 – BCD Addition
CSE 1325: Digital Logic Design 2
Binary Representation of Numbers

U • 231.45 =
• Here, 10 is called the radix or base of the number system

I •

In 10-base systems, there are 10 symbols (‘0’, ‘1’, … , ‘9’)
In n-base system, there are n symbols (‘0’, ‘1’, … , ‘n-1’)

U • In binary (2-base) system, there are 2 symbols (‘0’, and ‘1’)

3
Class Room Practice

U • Consider the binary number 101.011


• Calculate the decimal value of it.
I
U • The reverse process—converting a decimal to binary
—is also straightforward.
• Divide a decimal number is exact sum of positive and
negative power of 2.
• Successively divide by 2 and ½.

4
Decimal to Binary

U • Take decimal 14.875

I
U • Hence, 14 = 1110
• For fractional part, we have to divide by ½ or
multiply by 2.

• 14.875 = 1110.111 (binary)


5
Conversion Between Bases

U
I To convert from one base to another:

U 1) Convert the Integer Part


2) Convert the Fraction Part
3) Join the two results with a radix point

Aug 3, 2024 CSE 1325: Digital Logic Design 6


Conversion Details

U • To Convert the Integral Part:


Repeatedly divide the number by the new radix
I and save the remainders. The digits for the new
radix are the remainders in reverse order of their
U computation. If the new radix is > 10, then convert
all remainders > 10 to digits A, B, …
• To Convert the Fractional Part:
Repeatedly multiply the fraction by the new radix
and save the integer digits that result. The digits
for the new radix are the integer digits in order of
their computation. If the new radix is > 10, then
convert all integers > 10 to digits A, B, …
Aug 3, 2024 CSE 1325: Digital Logic Design 7
Example: Convert 46.687510 To Base 2

U • Convert 46 to Base 2
I
U • Convert 0.6875 to Base 2:

• Join the results together with the radix


point:

Aug 3, 2024 CSE 1325: Digital Logic Design 8


Checking the Conversion

U •To convert back, sum the digits times their


respective powers of r.
I •From the prior conversion of 46.687510
1011102 = 32 + 8 + 4 + 2
U = 46
0.10112 = 1/2 + 1/8 + 1/16
= 0.5000 + 0.1250 + 0.0625
= 0.6875

Aug 3, 2024 CSE 1325: Digital Logic Design 9


Class Room Practice

U • Convert decimal 17.375 to binary

I
U • 17.375 = 10001.011 (binary)

CSE 1325: Digital Logic Design 10


Additional Issue - Fractional Part

U • Note that in this conversion, the fractional


part became 0 as a result of the repeated
I multiplications.
• In general, it may take many bits to get this
U to happen or it may never happen.
• Example: Convert 0.6510 to N2
– 0.65 = 0.1010011001001 …
– The fractional part begins repeating every 4
steps yielding repeating 1001 forever!
• Solution: Specify number of bits to right of
radix point and round or truncate to this
number.
Aug 3, 2024 CSE 1325: Digital Logic Design 11
Any base → Decimal

U • Positive radix, positional number systems


• A number with radix r is represented by a string of
I digits:
An - 1An - 2 … A1A0 . A- 1 A- 2 … A- m + 1 A- m

U in which 0 £ Ai < r and . is the radix point.


• Find out the value of 657
• Find out the value of 243.235

Aug 3, 2024 CSE 1325: Digital Logic Design 12


Positive Powers of 2

U • Useful for Base Conversion


Exponent Value Exponent Value
I 0 1 11 2,048
1 2 12 4,096
U 2
3
4
8
13
14
8,192
16,384
4 16 15 32,768
5 32 16 65,536
6 64 17 131,072
7 128 18 262,144
8 256 19 524,288
9 512 20 1,048,576
10 1024 21 2,097,152
Aug 3, 2024 CSE 1325: Digital Logic Design 13
Commonly Occurring Bases

U Name Radix Digits

I Binary 2 0,1

U Octal
Decimal
8
10
0,1,2,3,4,5,6,7
0,1,2,3,4,5,6,7,8,9
Hexadecimal 16 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F

The six letters (in addition to the 10 integers) in


hexadecimal represent:

Aug 3, 2024 CSE 1325: Digital Logic Design 14


Numbers in Different Bases

U • Good idea to memorize!


I
Decimal Binary Octal Hexadecimal
(Base 10) (Base 2) (Base 8) (Base 16)
00 00000 00 00
01 00001 01 01

U 02
03
04
00010
00011
00100
02
03
04
02
03
04
05 00101 05 05
06 00110 06 06
07 00111 07 07
08 01000 10 08
09 01001 11 09
10 01010 12 0A
11 01011 13 0B
12 01100 14 0C
13 01101 15 0D
14 01110 16 0E
15 01111 17 0F
16 10000 20 10
Aug 3, 2024 CSE 1325: Digital Logic Design 15
Octal ↔ Binary

U •

8-base number system
8 symbols (0, 1, 2, 3, 4, 5, 6, 7)

I •

Base/radix is power of 2
One-to-one relation between octal and binary
U

• A binary number could be converted easily to octal


• Group 3 bits and convert directly to octal

CSE 1325: Digital Logic Design 16


Octal ↔ Binary

U • Octal to Binary:
Restate the octal as three binary digits

I starting at the radix point and going both
ways.
U • Binary to Octal:
– Group the binary digits into three bit
groups starting at the radix point and
going both ways, padding with zeros as
needed in the fractional part.
– Convert each group of three bits to an
octal digit.

Aug 3, 2024 CSE 1325: Digital Logic Design 17


Binary to Octal to Decimal

U
I
U

• Instead of converting binary to decimal


• Faster process is binary to octal to decimal

CSE 1325: Digital Logic Design 18


Hexadecimal ↔ Binary

U •

16-base number system
16 symbols (0—9, A, B, C, D, E)

I
Again radix is power of 2
• 4 bits to represent a hexadecimal number

CSE 1325: Digital Logic Design 19


Hexadecimal ↔ Binary

U
I
U

CSE 1325: Digital Logic Design 20


Octal to Hexadecimal via Binary

U • Convert octal to binary.


• Use groups of four bits and convert as
I above to hexadecimal digits.
U • Example: Octal to Binary to Hexadecimal
6 3 5 . 1 7 7 8

Aug 3, 2024 CSE 1325: Digital Logic Design 21


Binary Numbers and Binary Coding

U • Flexibility of representation
–Within constraints below, can assign any
I binary combination (called a code word)
to any data as long as data is uniquely
U encoded.
• Information Types
– Numeric
• Must represent range of data needed
• Very desirable to represent data such that simple,
straightforward computation for common arithmetic
operations permitted
• Tight relation to binary numbers
– Non-numeric
• Greater
CSEflexibility since
1325: Digital Logic arithmetic
Design operations not 22
Aug 3, 2024
applied.
Non-numeric Binary Codes

U • Given n binary digits (called bits), a binary


code is a mapping from a set of represented
I elements to a subset of the 2n binary
numbers.
U • Example: A
Color
Red
Binary Number
000
binary code Orange 001
Yellow 010
for the seven
Green 011
colors of the Blue 101
rainbow Indigo 110
Violet
• Code 100 is 111
not used
Aug 3, 2024 CSE 1325: Digital Logic Design 23
Number of Bits Required

U • Given M elements to be represented by a binary code, the


minimum number of bits, n, needed, satisfies the following

I
relationships:
2n > M > 2(n – 1)
n = log2 M where x , called the ceiling
U function, is the integer greater than or equal
to x.
• Example: How many bits are required to represent decimal
digits with a binary code?

Aug 3, 2024 CSE 1325: Digital Logic Design 24


Number of Elements Represented

U • Given n digits in radix r, there are rn distinct


elements that can be represented.
I • But, you can represent m elements, m < rn
• Examples:
U – You can represent 4 elements in radix r =
2 with n = 2 digits: (00, 01, 10, 11).
– You can represent 4 elements in radix r =
2 with n = 4 digits: (0001, 0010, 0100,
1000).

Aug 3, 2024 CSE 1325: Digital Logic Design 25


Binary Codes for Decimal Digits

U There are over 8,000 ways that you can chose 10


elements from the 16 binary numbers of 4 bits. A few

I are useful:
Decimal 8,4,2,1 Excess3 8,4,-2,-1 Gray
U 0
1
0000
0001
0011
0100
0000
0111
0000
0100
2 0010 0101 0110 0101
3 0011 0110 0101 0111
4 0100 0111 0100 0110
5 0101 1000 1011 0010
6 0110 1001 1010 0011
7 0111 1010 1001 0001
8 1000 1011 1000 1001
9 1001 1100 1111 1000

Aug 3, 2024 CSE 1325: Digital Logic Design 26


Binary Coded Decimal (BCD)

U • The BCD code is the 8,4,2,1 code.


• This code is the simplest, most intuitive
I binary code for decimal digits and uses the
U same powers of 2 as a binary number, but
only encodes the first ten values from 0 to
9.
• Example: 1001 (9) = 1000 (8) + 0001 (1)
• How many “invalid” code words are there?
• What are the “invalid” code words?

Aug 3, 2024 CSE 1325: Digital Logic Design 27


Warning: Conversion or Coding?

U • Do NOT mix up conversion of a decimal


number to a binary number with coding a
I decimal number with a BINARY CODE.

U • 1310 = 11012 (This is conversion)


• 13  0001|0011 (This is coding)

Aug 3, 2024 CSE 1325: Digital Logic Design 28


Binary Arithmetic
U • Single Bit Addition with Carry
• Multiple Bit Addition
I • BCD Addition
U

Aug 3, 2024 CSE 1325: Digital Logic Design 29


Single Bit Binary Addition with Carry

U Given two binary digits (X,Y), a carry in (Z) we get the


following sum (S) and carry (C):

I Carry in (Z) of 0: Z
X
0
0
0
0
0
1
0
1
U +Y
CS
+0
00
+1
01
+0
01
+1
10

Carry in (Z) of 1: Z 1 1 1 1
X 0 0 1 1
+Y +0 +1 +0 +1
CS 01 10 10 11

Aug 3, 2024 CSE 1325: Digital Logic Design 30


Multiple Bit Binary Addition

U • Extending this to two multiple bit examples:


Carries 0 0
I Augend 01100 10110
U Addend +10001 +10111
Sum

• Note: The 0 is the default Carry-In to the


least significant bit.

Aug 3, 2024 CSE 1325: Digital Logic Design 31


BCD Arithmetic
Given a BCD code, we use binary arithmetic to add the digits:
U +5
8 1000 Eight
+0101 Plus 5
I 13 1101 is 13 (> 9)
Note that the result is MORE THAN 9, so must be
represented by two digits!
U To correct the digit, subtract 10 by adding 6 modulo 16.
8 1000 Eight
+5 +0101 Plus 5
13 1101 is 13 (> 9)
+0110 so add 6
carry = 1 0011 leaving 3 + cy
0001 | 0011 Final answer (two digits)
If the digit sum is > 9, add one to the next significant digit
Aug 3, 2024 CSE 225: Digital Logic Design 32
BCD Addition Example

U
I
U

Aug 3, 2024 CSE 225: Digital Logic Design 33


BCD Addition Example
• Add 2905BCD to 1897BCD showing carries
U and digit corrections.

I
0001 1000 1001 0111
U + 0010 1001 0000 0101

Aug 3, 2024 CSE 225: Digital Logic Design 34

You might also like