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

Course Code: CSE 2203 Course Title: Digital Techniques: Department of Computer Science & Engineering

Uploaded by

Ishiza Marina
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views

Course Code: CSE 2203 Course Title: Digital Techniques: Department of Computer Science & Engineering

Uploaded by

Ishiza Marina
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 48

Heaven’s Light is Our Guide

Department of Computer Science & Engineering


Rajshahi University of Engineering & Technology, Bangladesh

Course Code: CSE 2203


Course Title: Digital Techniques

Presented by,
Md. Zahirul Islam
Binary Arithmetic

• Binary addition
• Binary subtraction
• Binary multiplication
• Binary division

2
Complements of Binary Numbers

• 1’s complements
• 2’s complements

3
Complements of Binary Numbers
• 1’s complement
• Change all 1s to 0s and all 0s to 1s
1 0 1 0 1 0 1 0

0 1 0 1 0 1 0 1

4
Complements of Binary Numbers
• 2’s complement
• Find 1’s complement and then add 1

1 0 1 0 1 0 1 0
1

1’s complement 0 1 0 1 0 1 0 1
Input bits
Adder Carry
Output bits (sum) In (add 1)

2’s complement 0 1 0 1 0 1 1 0
5
Signed Numbers

6
Topics for Signed Numbers

• Signed-magnitude form
• 1’s and 2’s complement form
• Decimal value of signed numbers
(How to convert)
• Range of values (max and min)
• Floating-point numbers

7
Signed Numbers

• Signed-magnitude form
– The sign bit is the left-most bit in a signed
binary number
– A 0 sign bit indicates a positive magnitude
– A 1 sign bit indicates a negative magnitude

8
Signed Numbers
• 1’s complement form
– A negative value is the 1’s complement of the
corresponding positive value
• 2’s complement form
– A negative value is the 2’s complement of the
corresponding positive value

9
Signed Numbers

• Decimal value of signed numbers


– Sign-magnitude
– 1’s complement
– 2’s complement

10
Signed Numbers

• Range of Values
Total combinations = 2n
2’s complement form:
– (2n – 1) to + (2n – 1 – 1)

Range for 8 bit number:


n=8
-(28-1) = -27 = -128 minimum
+(28-1) – 1 = +27 - 1 = +127 maximum
Total combination of numbers is 28 = 256.
11
Signed Numbers
Range for 16 bit number:
n = 16
-(216-1) = -215 = -32768 minimum
+(216-1) - 1 = +215 = +32767 maximum
Total combinations is 216 = 65536 (64K)
8 bit examples:
10000000 = -128
11111111 = -1
10000001 = -127
01111111 = +127
12
Arithmetic Operations with Signed
Numbers

• Addition
• Subtraction
• Multiplication
• Division

13
Arithmetic Operations with Signed
Numbers
Addition of Signed Numbers
• The parts of an addition function are:
– Augend - The first number
– Addend - The second number
– Sum - The result
Numbers are always added two at a time.

14
Arithmetic Operations with Signed
Numbers
Four conditions for adding numbers:
1. Both numbers are positive.
2. A positive number that is larger than a
negative number.
3. A negative number that is larger than a
positive number.
4. Both numbers are negative.

15
Arithmetic Operations with Signed
Numbers
Signs for Addition
• When both numbers are positive, the sum is
positive.
• When the larger number is positive and the
smaller is negative, the sum is positive. The
carry is discarded.

16
Arithmetic Operations with Signed
Numbers
Signs for Addition
• When the larger number is negative and the
smaller is positive, the sum is negative (2’s
complement form).
• When both numbers are negative, the sum
is negative (2’s complement form). The
carry bit is discarded.

17
Examples (8 bit numbers)
• Add 7 and 4 (both positive) 00000111 7
+00000100 +4
00001011 11

• Add 15 and -6 (positive > negative) 00001111 15


+11111010 + -6
Discard carry 1 00001001 9

• Add 16 and -24 (negative > positive) 00010000 16


+11101000 + -24
Sign bit is negative so negative 11111000 -8
number in 2’s complement form

• Add -5 and -9 (both negative) 11111011 -5


+11110111 + -9
Discard carry 1 11110010 -14
18
Arithmetic Operations with Signed
Numbers
Subtraction of Signed Numbers
• The parts of a subtraction function are:
– Minuend - The first number
– Subtrahend - The second number
– Difference - The result
Subtraction is addition with the sign of the
subtrahend changed.

19
Arithmetic Operations with Signed
Numbers
Subtraction
• The sign of a positive or negative binary
number is changed by taking its 2’s
complement
• To subtract two signed numbers, take the
2’s complement of the subtrahend and add.
Discard any final carry bit.

20
Subtraction Examples
• Find 8 minus 3. 00001000 8 Minuend
+11111101 -3 Subtrahend
Discard carry 1 00000101 5 Difference

• Find 12 minus -9. 00001100 12


+00001001 - -9
00010101 21

• Find -25 minus 19. 11100111 -25


+11101101 - 19
Discard carry 1 11010100 -44

• Find -120 minus -30. 10001000 -120


+00011110 - -30
10100110 -90

21
Arithmetic Operations with Signed
Numbers
Multiplication of Signed Numbers
• The parts of a multiplication function are:
– Multiplicand - First number
– Multiplier - Second number
– Product - Result
Multiplication is equivalent to adding a
number to itself a number of times equal to
the multiplier.

22
Arithmetic Operations with Signed
Numbers
There are two methods for multiplication:
• Direct addition
– add multiplicand multiple times equal to the
multiplier
– Can take a long time if multiplier is large
• Partial products
– Similar to long hand multiplication
The method of partial products is the most
commonly used.
23
Arithmetic Operations with Signed
Numbers
Multiplication of Signed Numbers
• If the signs are the same, the product is
positive. (+ X + = + or - X - = +)
• If the signs are different, the product is
negative. (+ X - = - or - X + = -)

24
Multiplication Example
• Both numbers must be in uncomplemented form
• Multiply 3 by -5.
Opposite signs, so product will be negative.
310 = 000000112 00000011 Multiplicand
X 00000101 Multiplier
-510 = 111110112 00000011 First partial product
+ 0000000 Second partial product
00000011 Sum of 1st and 2nd
2’s complement of -5 + 000011 Third partial product
00000101 00001111 Sum and Final Product

Final result is negative, so take 2’s complement.


11110001 is the result which in decimal is -15.

25
Arithmetic Operations with Signed
Numbers
Division of Signed Numbers
• The parts of a division operation are:
– Dividend
dividend
– Divisor  quotient
divisor
– Quotient
Division is equivalent to subtracting the
divisor from the dividend a number of
times equal to the quotient.

26
Arithmetic Operations with Signed
Numbers

Division of Signed Numbers


• If the signs are the same, the quotient is
positive. (+ ÷ + = + or - ÷ - = +)
• If the signs are different, the quotient is
negative. (+ ÷ - = - or - ÷ + = -)

27
Division Example
• Both numbers must be in uncomplemented form
• Divide 01100100 by 00110010.
Both numbers are positive so
quotient will be positive.
Set the quotient to zero initially. quotient: 00000000
01100100 Dividend
Subtract the divisor from the + 11001110 2’s complement of Divisor
dividend by using 2’s complement
1 00110010 First partial remainder
addition. (11001110)
Ignore the carry bit. Add 1 to quotient: 00000000
00110010 + 1remainder
First partial = 00000001
Subtract the divisor from the + 11001110 2’s complement of Divisor
1st partial remainder using 2’s
complement addition. 1 00000000 zero remainder
So final quotient is 00000010 and final
Addremainder is 00000000
1 to quotient: 00000001 + 1 = 00000010
28
BCD Code
• Binary Coded Decimal (BCD) is a widely used
way to present decimal numbers in binary form.
– Combines features of both decimal and binary
systems.
• Each digit is converted to a binary equivalent.
• BCD is not a number system.
– It is a decimal number with each digit encoded
to its binary equivalent.
• A BCD number is not the same as a straight
binary number.
– The primary advantage of BCD is the relative
ease of converting to and from decimal.
Copyright ©2007 by Pearson Education, Inc.
Columbus, OH 43235
All rights reserved.
BCD Code
• Convert the number 87410 to BCD:
– Each decimal digit is represented using 4 bits.
• Each 4-bit group can never be greater than 9.

• Reverse the process to convert BCD to decimal.

Ronald Tocci/Neal Widmer/Gregory Moss


Copyright ©2007 by Pearson Education, Inc.
Digital Systems: Principles and Applications, 10e
Columbus, OH 43235
All rights reserved.
BCD Code
• Convert 0110100000111001 (BCD) to its
decimal equivalent.

Divide the BCD number into four-bit


groups and convert each to decimal.

Copyright ©2007 by Pearson Education, Inc.


Columbus, OH 43235
All rights reserved.
BCD Code
• Convert 0110100000111001 (BCD) to its
decimal equivalent.

Divide the BCD number into four-bit


groups and convert each to decimal.

Ronald Tocci/Neal Widmer/Gregory Moss


Copyright ©2007 by Pearson Education, Inc.
Digital Systems: Principles and Applications, 10e
Columbus, OH 43235
All rights reserved.
BCD Code
• Convert BCD 011111000001 to its decimal
equivalent.

The forbidden group represents


an error in the BCD number.

Ronald Tocci/Neal Widmer/Gregory Moss


Copyright ©2007 by Pearson Education, Inc.
Digital Systems: Principles and Applications, 10e
Columbus, OH 43235
All rights reserved.
The Gray Code
• The Gray code is used in applications where
numbers change rapidly.
– Only one bit changes from each value to the next.

Three bit binary


and Gray code
equivalents.

Ronald Tocci/Neal Widmer/Gregory Moss


Copyright ©2007 by Pearson Education, Inc.
Digital Systems: Principles and Applications, 10e
Columbus, OH 43235
All rights reserved.
The Gray Code

Binary to Gray Gray to Binary

Ronald Tocci/Neal Widmer/Gregory Moss


Copyright ©2007 by Pearson Education, Inc.
Digital Systems: Principles and Applications, 10e
Columbus, OH 43235
All rights reserved.
The Gray Code
An eight-position,
three-bit shaft
encoder

These devices produce a binary


value that represents the position
of a rotating mechanical shaft.

Ronald Tocci/Neal Widmer/Gregory Moss


Copyright ©2007 by Pearson Education, Inc.
Digital Systems: Principles and Applications, 10e
Columbus, OH 43235
All rights reserved.
Putting It All Together
Decimal numbers 1 – 15 in binary, hex, BCD, Gray

Ronald Tocci/Neal Widmer/Gregory Moss


Copyright ©2007 by Pearson Education, Inc.
Digital Systems: Principles and Applications, 10e
Columbus, OH 43235
All rights reserved.
The Byte, Nibble, and Word
• Most microcomputers handle and store binary data
and information in groups of eight bits.
– 8 bits = 1 byte.
• A byte can represent numerous types of data/information.
• Binary numbers are often broken into groups
of four bits.
– Because a group of four bits is half as big as a
byte, it was named a nibble.
• A word is a group of bits that represents a
certain unit of information.
– Word size can be defined as the number of bits
in the binary word a digital system operates on.
• PC word size is eight bytes (64 bits).
Ronald Tocci/Neal Widmer/Gregory Moss
Copyright ©2007 by Pearson Education, Inc.
Digital Systems: Principles and Applications, 10e
Columbus, OH 43235
All rights reserved.
Alphanumeric Codes
• Represents characters and functions found on
a computer keyboard.
– 26 lowercase & 26 uppercase letters, 10 digits,
7 punctuation marks, 20 to 40 other characters.
• ASCII – American Standard Code for
Information Interchange.
– Seven bit code: 27 = 128 possible code groups
– Examples of use: transfer information between
computers; computers & printers; internal
storage.
Ronald Tocci/Neal Widmer/Gregory Moss
Copyright ©2007 by Pearson Education, Inc.
Digital Systems: Principles and Applications, 10e
Columbus, OH 43235
All rights reserved.
Alphanumeric Codes
ASCII – American Standard Code
for Information Interchange

See the entire table of your textbook.


Ronald Tocci/Neal Widmer/Gregory Moss
Copyright ©2007 by Pearson Education, Inc.
Digital Systems: Principles and Applications, 10e
Columbus, OH 43235
All rights reserved.
Parity Method for Error Detection
• Binary data and codes are frequently moved
between locations:
– Digitized voice over a microwave link.
– Storage/retrieval of data from magnetic/optical disks.
– Communication between computer systems
over telephone lines, using a modem.

Ronald Tocci/Neal Widmer/Gregory Moss


Copyright ©2007 by Pearson Education, Inc.
Digital Systems: Principles and Applications, 10e
Columbus, OH 43235
All rights reserved.
Parity Method for Error Detection
• Electrical noise can cause errors during
transmission.
– Spurious fluctuations in voltage or current present
in all electronic systems.

• Many digital systems employ methods for error


detection—and sometimes correction.
– One of the simplest and most widely used schemes
for error detection is the parity method.
Ronald Tocci/Neal Widmer/Gregory Moss
Digital Systems: Principles and Applications, 10e Copyright ©2007 by Pearson Education, Inc.
Columbus, OH 43235
All rights reserved.
Parity Method for Error Detection
• The parity method of error detection requires
the addition of an extra bit to a code group.
– Called the parity bit, it can be either a 0 or 1,
depending on the number of 1s in the code group.
• There are two parity methods, even and odd.
– The transmitter and receiver must “agree” on
the type of parity checking used.
• Even seems to be used more often.

Ronald Tocci/Neal Widmer/Gregory Moss


Copyright ©2007 by Pearson Education, Inc.
Digital Systems: Principles and Applications, 10e
Columbus, OH 43235
All rights reserved.
Parity Method for Error Detection
• Even parity method—the total number of bits
in
a group including the parity bit must add up to
an even number.
– The binary group 1 0 1 1 would require the
addition
of a parity bit 1, making the group 1 1 0 1 1.
1
• The parity bit may be added at either end of a group.

Ronald Tocci/Neal Widmer/Gregory Moss


Copyright ©2007 by Pearson Education, Inc.
Digital Systems: Principles and Applications, 10e
Columbus, OH 43235
All rights reserved.
Parity Method for Error Detection
• Odd parity method—the total number of bits
in a group including the parity bit must add up
to an odd number.
– The binary group 1 1 1 1 would require the
addition
of a parity bit 1, making the group 1 1 1 1 1.
1
The parity bit becomes a part of the code word.
Adding a parity bit to the seven-bit ASCII
code produces an eight-bit code.

Ronald Tocci/Neal Widmer/Gregory Moss


Copyright ©2007 by Pearson Education, Inc.
Digital Systems: Principles and Applications, 10e
Columbus, OH 43235
All rights reserved.
Applications
• When ASCII characters are transmitted there
must be a way to tell the receiver a new
character is coming.
– There is often a need to detect errors in the
transmission as well.
• The method of transfer is called asynchronous data
communication.
Applications
• An ASCII character must be “framed” so the
receiver knows where the data begins and ends.
– The first bit must always be a start bit (logic 0).
• ASCII code is sent LSB first and MSB last.
– After the MSB, a parity bit is appended to check
for transmission errors.
– Transmission is ended by sending a stop bit (logic 1).
Thank You

You might also like