DLD Lecture 03
DLD Lecture 03
Wondershare
Watermark PDFelement
Presented by,
Prof. Dr. Boshir Ahmed
Md. Zahirul Islam
Remove
Wondershare
Watermark PDFelement
Binary Arithmetic
• Binary addition
• Binary subtraction
• Binary multiplication
• Binary division
2
Remove
Wondershare
Watermark PDFelement
• 1’s complements
• 2’s complements
3
Remove
Wondershare
Watermark PDFelement
• 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
Remove
Wondershare
Watermark PDFelement
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
Remove
Wondershare
Watermark PDFelement
Signed Numbers
6
Remove
Wondershare
Watermark PDFelement
• 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
Remove
Wondershare
Watermark PDFelement
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
Remove
Wondershare
Watermark PDFelement
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
Remove
Wondershare
Watermark PDFelement
Signed Numbers
10
Remove
Wondershare
Watermark PDFelement
Signed Numbers
• Range of Values
Total combinations = 2n
2’s complement form:
– (2n – 1) to + (2n – 1 – 1)
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
Remove
Wondershare
Watermark PDFelement
• Addition
• Subtraction
• Multiplication
• Division
13
Remove
Wondershare
Watermark PDFelement
14
Remove
Wondershare
Watermark PDFelement
15
Remove
Wondershare
Watermark PDFelement
16
Remove
Wondershare
Watermark PDFelement
17
Remove
Wondershare
Watermark PDFelement
19
Remove
Wondershare
Watermark PDFelement
20
Remove
Wondershare
Watermark PDFelement
Subtraction Examples
• Find 8 minus 3. 00001000 8 Minuend
+11111101 - 3 Subtrahend
Discard carry 1 00000101 5 Difference
21
Remove
Wondershare
Watermark PDFelement
22
Remove
Wondershare
Watermark PDFelement
24
Remove
Wondershare
Watermark PDFelement
Multiplication Example
• Both numbers must be in uncomplemented form
• Multiply 3 by -5.
Opposite signs, so product will be negative.
310 = 000000112 00000011 Multiplicand
-510 = 111110112 X 00000101 Multiplier
00000011 First partial product
+ 0000000 Second partial product
00000011 Sum of 1st and 2nd
+ 000011 Third partial product
00001111 Sum and Final Product
25
Remove
Wondershare
Watermark PDFelement
26
Remove
Wondershare
Watermark PDFelement
27
Remove
Wondershare
Watermark PDFelement
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)
Add 1 to quotient: 00000000 + 1 = 00000001
Ignore the carry bit.
00110010 First partial remainder
Subtract the divisor from the + 11001110 2’s complement of Divisor
1st partial remainder using 2’s 1 00000000 zero remainder
complement addition.
Add 1 to quotient: 00000001 + 1 = 00000010
So final quotient is 00000010 and final remainder is 00000000 28
Remove
Wondershare
Watermark PDFelement
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.
Remove
Wondershare
Watermark PDFelement
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.
BCD Code
• Convert 0110100000111001 (BCD) to its
decimal equivalent.
BCD Code
• Convert 0110100000111001 (BCD) to its
decimal equivalent.
BCD Code
• Convert BCD 011111000001 to its decimal
equivalent.
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.
Remove
Wondershare
Watermark PDFelement
Alphanumeric Codes
ASCII – American Standard Code
for Information Interchange
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.
Remove
Wondershare
Watermark PDFelement
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).
Remove
Wondershare
Watermark PDFelement
Thank
You
Next topic