Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Lecture4 Chapter1 - Binary - Gray, and ASCII Codes

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

Chapter1: Digital Systems and Binary

Numbers
Lecture4- Study Binary Codes and Binary Logic
Engr. Arshad Nazir, Asst Prof
Dept of Electrical Engineering
EE-223 Digital Logic Design Spring 2024 SEECS 1
Objectives
• Study Binary , Gray Code, and ASCII Codes
• Perform Arithmetic operations in BCD using 10’s
Complement method
• Parity generation and checking
• Binary Logic

EE-223 Digital Logic Design Spring 2024 2


Binary Codes
• Digital systems use discrete elements of information represented with
binary codes (i.e., a pattern of 0’s and 1’s). The codes should be in binary
because computers have circuits that represent and manipulate 0’s and
1’s.
• An n-bit binary code is a group of n bits that can represent up to 2n distinct
combinations of 1’s and 0’s.
➢ Each distinct combination represents a single symbol in the computer.
➢ The bit combination of an n-bit code is determined from the count in
binary from 0 to 2n-1. Each element must be assigned a unique binary
bit combination, and no two elements can have the same value.
• Although the minimum number of bits required to code 2n distinct
quantities is n, there is no maximum number of bits that can be used for a
binary code.
• Codes can be categorized as numeric and alphanumeric used for numbers
and transmission of textual data.
EE-223 Digital Logic Design Spring 2024 3
BCD Code (8,4,2,1)
• The most common representation for binary digits is the binary coded
decimal (BCD) form which is a binary assignment of the decimal numbers.
➢ This code is the simplest, most intuitive binary code for decimal digits
and uses the same weights as a binary number, but only encodes the
first ten values from 0 to 9 (6 out of 16 possible combinations remains
unassigned ).
➢ A number with k distinct decimal digits will require 4k bits in BCD.
➢ Each digit of a decimal value is converted to its respective binary
representation.
➢ BCD number needs more bits than its equivalent binary value?
• Each decimal digit in BCD code can be represented as shown in the next
slide.
Binary Coded Decimal Code (BCD)

EE-223 Digital Logic Design Spring 2024 5


BCD Addition
• BCD only represents each of the decimal digitals 0 through 9 as a single 4-bit
binary value. BCD is a numeral code used in arithmetic operations in digital
machines. Addition is the most important operation because the other three
operations (subtraction, multiplication, and division can be accomplished using
addition. Following rules apply:
➢ Add the two BCD numbers, using the rules of binary addition.
➢ If a 4-bit sum is equal to or less than 9, it is a valid BCD number.
➢ If a 4-bit sum is greater than 9, or if a carry out of the 4-bit group is generated,
it is an invalid result. Add 6(0110) to the 4-bit sum in order to skip the invalid
states and return the code to 8421. If a carry results when 6 is added, simply
add the carry to the next significant 4-bit group.
• Some BCD addition examples are:

EE-223 Digital Logic Design Spring 2024 6


Multi-Digit BCD Addition

EE-223 Digital Logic Design Spring 2024 7


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
• As an example, imagine we want to add
(+257) + (-160) = +97 Are these signed?

• 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
Perform subtraction (-257) - (+160) both signed and unsigned?
EE-223 Digital Logic Design Spring 2024 8
Other Decimal Codes
• There are various other decimal codes that can be used:
➢ BCD (8, 4, 2, 1)
➢ 2, 4, 2, 1
➢ Excess-3 code. (adds binary 0011 to the BCD code)
➢ 8, 4, -2, -1
➢ Gray Code
➢ ASCII Character Code
➢ Error-Detecting Code
• Each bit has a "weight" associated with it and you can compute the
decimal value by adding the weights where a 1 exists in the code-
word.

EE-223 Digital Logic Design Spring 2024 9


Four Different Binary Codes

EE-223 Digital Logic Design Spring 2024 10


Gray Code
• The Gray (reflected) code is named after Frank Gray who patented it
for shaft encoders in 1953. It is un-weighted and non-arithmetic code;
that is, there are no specific weights assigned to the bit positions
• Some of the uses of Gray code are:-
➢ Conversion of physical variables like position or voltage that have a
continuous range of values to a digital representation.
➢ A different use of Gray codes appears in low-power CMOS logic
circuits that count up or down.
• Gray code is cyclic code i.e any n-bit code can be generated form n-1
bit code by taking reflection along the mirror and padding the two
halves with 0’s and 1’s respectively.
• The advantage of Gray code over straight binary number sequence is
that only one bit in the code group changes when going from one
number to the next (unit distance code).

EE-223 Digital Logic Design Spring 2024 11


Gray Code Cont…
• This property is important in many applications, such as optical shaft angle
encoders, where error susceptibility increases with the number of bit
changes between adjacent numbers in a sequence.
• Optical shaft encoder is a disc attached to rotating shaft to measure its
rotational position. The disc contains areas that are clear for binary 1 and
opaque for binary 0. An illumination source is placed on one side of the
disc, and optical sensors, one for each of the bits to be encoded are placed
on the other side of the disc. When a clear region lies between the source
and a sensor, the sensor responds to the light with a binary 1 output. When
opaque region lies between the source and the sensor, the sensor
responds to the dark with a binary 0.
• The optical shaft encoder using 3-Bit Gray code for positions 0 through 7 is
shown in the next slide.

EE-223 Digital Logic Design Spring 2024 12


EE-223 Digital Logic Design Spring 2024 13
Gray Code Vs Binary Code
• Compare the number of bits
changing when going from
one number to the next for a
three-bit Binary and Gray
Code:
➢ In Gray code it is always
1-bit change (unit-
distance code).
➢ Can you guess the
applications where this
important property can
be used in digital
applications?
EE-223 Digital Logic Design Spring 2024 14
Gray Code
Cont…

EE-223 Digital Logic Design Spring 2024 15


Conversion from Binary to Gray Code
• Binary to Gray code Conversion: The following rules apply:
➢ The most significant bit (left-most) in the Gray code is the same as the
corresponding MSB in the binary number.
➢ Going from left to right, add each adjacent pair of binary code bits to get the
next Gray code bit and discard carries. Which addition?

➢ For example, the conversion of binary number 10110 to Gray Code is as follows

➢ The Gray Code is 11101.


EE-223 Digital Logic Design Spring 2024 16
Conversion from Gray to Binary Code
• Gray to Binary code Conversion: The following rules apply:
➢ The most significant bit (left-most) in the Binary code is the same as the
corresponding MSB in the Gray code.
➢ Add each Binary code bit generated to the Gray code bit in the next adjacent
position and discard carries.

➢ For example, the conversion of Gray number 11011 to Binary code is as follows

➢ The binary number is 10010.


EE-223 Digital Logic Design Spring 2024 17
ASCII Character Code
• The American Standard Code for Information Interchange (ASCII) uses seven
bits to code 128 characters.
• The ASCII code contains 94 graphic characters that are printable and 34
nonprinting characters used for various control functions. The graphic
characters consist of the 26 uppercase letters (A through Z), the 26 lowercase
letters (a through z), the 10 numerals (0 through 9), and 32 special characters,
such as %, *, and $.
• The 34 control characters are designated in the ASCII table with abbreviated
names. They are listed again in the table with their function names. The
control characters are used for routing data and arranging the printed text into
a prescribed format.
➢ The following ASCII chart allows you to specify the characters in decimal
representation by concatenating the column headings to the row headings.
For example, the character 5 is represented in binary as 0110101
EE-223 Digital Logic Design Spring 2024 18
ASCII Table

EE-223 Digital Logic Design Spring 2024 19


ASCII Table (Cont …

EE-223 Digital Logic Design Spring 2024 20


Error-Detecting Code
• Error-Detecting uses an eighth bit (added to 7-bit ASCII character) to indicate parity.
➢ A parity bit is an extra bit that is set to 0 or 1 as needed to make the total
number of 1’s either even or odd.
➢ In an odd-parity code, the parity bit is specified so that the total number of ones
is odd.
➢ In an even-parity code, the parity bit is specified so that the total number of
ones is even.
➢ It detects one, three or any odd combination of errors but even combination of
errors is undetected.
P Information Bits
1 1 0 0 0 0 1 1 0 1 0 0 0 0 1 1
 
Added even parity bit Added odd parity bit

EE-223 Digital Logic Design Spring 2024 21


Parity Code Example
• Concatenate a parity bit to the ASCII code for the characters 0, X, and
= to produce both odd-parity and even-parity codes.

Character ASCII Odd-Parity Even-Parity


ASCII ASCII

0 0110000 10110000 00110000

X 1011000 01011000 11011000

= 0111100 10111100 00111100

EE-223 Digital Logic Design Spring 2024 22


Binary Storage
• Binary storage represents the storage mechanisms for binary data
stored in a computer.
➢ A binary cell is a device that possesses two stable states, and it
can store a single state value (0 or 1). It stores single bit of data.
examples: flip-flop circuits, ferrite cores, capacitor
➢ A register is a group of binary cells. n cells allows the register to
store n bits and thus 2n possible states.
o The type of information (BCD, ASCII, etc.) stored in a register
has to be agreed upon by the users of the register.

0 0 1 0 1 0 1 1

Binary Cell
EE-223 Digital Logic Design Spring 2024 23
Register Transfer
• A register transfer operation involves the transfer of binary
information from one set of binary registers into other set of binary
registers.
• The capture and storage of information requires:
➢ An input register to store the key inputs from the keyboard
➢ A processor register to store the data when processed by the CPU
➢ A memory register in the memory unit to store the values

EE-223 Digital Logic Design Spring 2024 24


Register Transfer

• Data input at keyboard


• Shifted into place
• Stored in memory

➢ NOTE: Data input in ASCII

EE-223 Digital Logic Design Spring 2024 25


Binary Information Processing
• The actual processing of binary information in a computer is
completed by digital logic circuits which have been implemented to
serve a specific purpose (i.e. addition).
➢ The registers are accessed (read and write) when they are
needed to complete an operation. For example we need two
register sets to store two values to be added and a register set to
store the result of the sum.
o Furthermore, we need three registers in both the memory
unit and in the processor.

EE-223 Digital Logic Design Spring 2024 26


Example Binary Information
Processing
• We need processing
• We need storage
• We need communication

EE-223 Digital Logic Design Spring 2024 27


Binary Logic
• Binary logic consists of binary variables and logical operations.
➢ The variables are designated by letters of the alphabet (A, B, C, x,
y, z, etc.).
➢ There are three basic logical operations:
o AND
o OR
o NOT

EE-223 Digital Logic Design Spring 2024 28


Logical Operations
• AND is represented by a dot or the absence of an operator.
➢ x·y = z or xy = z
➢ Read as “x and y is equal to z”
➢ Means that z=1 if and only if x=1 and y=1
• OR is represented by a plus sign.
➢ x+y = z
➢ Read as “x or y is equal to z”
➢ Means that z=1 if x=1 or y=1 or both x=1 and y=1
• NOT is represented by a prime or an over bar.
➢ x´=z or x = z
➢ Read as “not x is equal to z”
➢ Means that if x=1 then z=0 or if x=0 then z=1

EE-223 Digital Logic Design Spring 2024 29


Truth Tables
• Since each binary variable consists of value of 0 or 1, each
combination of values for the variables involved in a binary operation
has a specific result value.
• A truth table is a method of visualizing all possible combinations of
the input values and the respective output values that occur due to
the operation on the specified combination.
AND OR NOT
A B A.B A B A+B A A′
0 0 0 0 0 0
0 1
0 1 0 0 1 1
1 0
1 0 0 1 0 1
1 1 1 1 1 1

EE-223 Digital Logic Design Spring 2024 30


Logic Gates
• Logic gates are electronic circuits that operate on one or more input
signals to produce an output signal.
➢ The state (high-low, on-off) of electricity on a line represents each of
the two states for binary representation (1 or 0).
• Logic Gate Symbols

EE-223 Digital Logic Design Spring 2024 31


AND Logic Function
• Using door • Using Switches
➢ Both doors are ➢Switches are input
opened to pass the and LED is output
light ➢Both witches closed
(ON) to give output

EE-223 Digital Logic Design Spring 2024 32


EE-223 Digital Logic Design Spring 2024 33
Timing Diagram

EE-223 Digital Logic Design Spring 2024 34


Multi-Input Circuits

EE-223 Digital Logic Design Spring 2024 35


The End

EE-223 Digital Logic Design Spring 2024 36

You might also like