2. Objectives
• Addition, subtraction, multiplication, and division
of two binary numbers.
• Addition and subtraction of hexadecimal numbers
• Difference between binary addition and OR addition.
• Comparison among three different systems for
representing signed numbers.
• Manipulate signed binary numbers using the 2’s –
complement system.
• BCD adder circuit and addition process.
• Basic operation of an arithmetic/logic unit
3. Binary Addition
• The addition of two binary numbers is performed in
exactly the same manner as the addition of decimal
numbers.
• Least-significant-digit first.
• “Carry” of 1 into the next position may be needed.
• 4 different cases for binary addition
position
next
into
1
of
carry
1
11
1
1
1
position
next
into
1
of
carry
0
10
1
1
1
0
1
0
0
0
•The operations of subtraction, multiplication, and division
actually use only addition as their basic operation
7. Sign-magnitude system: represents + and –
numbers, but we need to design special circuits
to add positive and negative numbers.
ex: 5 + (-5) = 0
use 8 bit signed-binary numbers and add using
full-adder circuits :
0 0 0 0 0 1 0 1 ( 5)
+ 1 0 0 0 0 1 0 1 (-5)
_____________________
1 0 0 0 1 0 1 0 (-10)
8. 1’s complement system
– Change each 0 to 1, and each 1 to 0.
– Example
(45) 1 0 1 1 0 1 original binary number
(-45) 0 1 0 0 1 0 complement each bit
1 0 1 1 0 1 (45)
+ 0 1 0 0 1 0 (-45)
____________________
1 1 1 1 1 1
Add one to this result, get zero.
9. 2’s complement of a binary number:
– Take the 1’s complement of the number
– Add 1 to the least-significant-bit position
number
binary
original
of
complement
s
2'
010011
complement
s
2'
form
to
1
add
1
complement
s
1'
form
bit to
each
complement
010010
45
of
equivalent
binary
101101
10. Representing signed numbers
using 2’s complement form
• If the number is positive, the magnitude is
represented in its positional-weighted binary form,
and a sign bit of 0 is placed in front of the MSB.
• If the number is negative, the magnitude is
represented in its 2’s complement form, and a sign
bit of 1 is placed in front of the MSB.
12. Example
• Represent each of the following signed decimal
numbers as a signed binary number in the 2’s-
complement system. Use a total of five bits including
the sign bit.
(a) +13 (b) –9 (c) +3 (d) –2 (e) -8
13. Negation
• Negation is the operation of converting a postive
number to its negative equivalent or a negative
number to its positive equivalent.
• We negate a signed binary number by 2’s-complementing
it.
• Example
– Each of the following numbers is a signed binary
number in the 2’s-complement system. Determine the
decimal value in each case:
(a)01100 (b) 11010 (c)10001
14. Special case in 2’s-complement
representation
• Whenever a signed number has a 1 in the sign bit and
all 0s for the magnitude bits, its decimal equivalent
is –2N, where N is the number of bits in the
magnitude.
• The complete range of values that can be represented
in the 2’s-complement system having N magnitude bits
is –2N to +(2N - 1).
• What is the range of unsigned decimal values that can
be represented in a byte?
• What is the range of signed decimal values that can
be represented in a byte?
16. Addition in the 2’s-complement
system
• Case I: Two Postive Numbers.
+9 0 1001 (augend)
+4 0 0100 (addend)
0 1101 (sum = +13)
Sign bits
17. Addition, cont.
• Case II: Positive Number and Smaller Negative Number
+9 0 1001 (augend)
-4 1 1100 (addend)
1 0 0101
Sign bits
This carry is disregarded; the result
is 01001(sum=+5)
18. Addition, cont.
• Case III: Positive Number and Larger Negative Number
-9 10111
+4 00100
11011 (sum = -5)
Negative sign bit
19. Addition, cont.
• Case IV: two negative Numbers
-9 10111
-4 11100
1 10011
Sign bit
This carry is disregarded; the result is
10011(sum =-13)
20. Addition, cont.
• Case V: Equal and Opposite Numbers
-9 10111
+9 01001
0 100000
Disregard; the result is
00000(sum = +0)
21. Review Questions
• Assume the 2’s complement system for both questions
– True or False: Whenever the sum of two signed
binary numbers has a sign bit of 1, the magnitude
of the sum is in 2’s complement form.
– Add the following pairs of signed numbers. Express
the sum as a signed binary number and as a decimal
number
• (a) 100111+111011
• (b) 100111+011001
22. Subtraction in the 2’s-
complement System
• The procedure for subtracting one binary number(the
subtrahend) from another binary number(the minuend)
– Negate the subtrahend. This will change the
subtrahend to its equivalent value of opposite
sign.
– Add this to the minuend. The result of this
addition will represent the difference between the
subtrahend and the minuend.
23. Arithmetic Overflow
• When two positive or two negative numbers are being
added, an overflow could occur if there is a carry
happening to the sign-bit position.
• Overflow can occur when the minuend and subtrahend
have different signs.
24. Review Questions
• Perform the subtraction on the following pairs of
signed numbers using the 2’s-complement system.
Express the results as signed binary numbers and as
decimal values.
(a)01001-11010 (b)10010-10011
• How can arithmetic overflow be detected when signed
numbers are being added? Subtracted?
25. Multiplication of Binary
numbers
• The same manner as the multiplication of decimal
numbers.
1001 multiplicand = 910
1011 multiplier=1110
1001
1001
0000
1001
1100011 final product = 9910
26. Multiplication in the 2’s-
Complement System
• If the two numbers to be multiplied are positive,
they are already in true binary form and are
multiplied as they are.
• When the two numbers are negative, they will be in
2’s-complement form. Each is converted to a positive
number, and then the two numbers are multiplied. The
product is kept as a positive number and is given a
sign bit of 0.
• When one of the number is positive and the other is
negative, the negative number is first converted to a
positive magnitude by taking its 2’s complement. The
product will be in true-magnitude form, should be
changed to 2’s complement form and given a sign bit
of 1.
28. Binary Division
• The same as for decimal numbers---long division
0
11
0011
011
1001
0010
11
0
100
100
100
1
.
0010
0
.
1010
100
The division of signed numbers is handled
in the same way as multiplication.
29. 1.7 Binary Codes
• BCD Code
– A number with k decimal
digits will require 4k bits
in BCD.
– Decimal 396 is represented
in BCD with 12bits as 0011
1001 0110, with each group
of 4 bits representing one
decimal digit.
– A decimal number in BCD is
the same as its equivalent
binary number only when the
number is between 0 and 9.
– The binary combinations 1010
through 1111 are not used
and have no meaning in BCD.
30. Binary Code
• Example:
– Consider decimal 185 and its corresponding value
in BCD and binary:
• BCD addition
31. Binary Code
• Example:
– Consider the addition of 184 + 576 = 760 in BCD:
• Decimal Arithmetic: (+375) + (-240) = +135
Hint 6: using 10’s of BCD
33. Binary Codes)
• Gray Code
– The advantage is that only
bit in the code group
changes in going from one
number to the next.
• Error detection.
• Representation of analog
data.
• Low power design.
000 001
010
100
110 111
101
011
1-1 and onto!!
36. ASCII Character Codes
• American Standard Code for Information Interchange
(Refer to Table 1.7)
• A popular code used to represent information sent as
character-based data.
• It uses 7-bits to represent:
– 94 Graphic printing characters.
– 34 Non-printing characters.
• Some non-printing characters are used for text format
(e.g. BS = Backspace, CR = carriage return).
• Other non-printing characters are used for record
marking and flow control (e.g. STX and ETX start and
end text areas).
37. ASCII Properties
• ASCII has some interesting properties:
– Digits 0 to 9 span Hexadecimal values 3016 to 3916
– Upper case A-Z span 4116 to 5A16
– Lower case a-z span 6116 to 7A16
• Lower to upper case translation (and vice versa)
occurs by flipping bit 6.
38. Binary Codes
• Error-Detecting Code
– To detect errors in data communication and
processing, an eighth bit is sometimes added to
the ASCII character to indicate its parity.
– A parity bit is an extra bit included with a
message to make the total number of 1's either
even or odd.
• Example:
– Consider the following two characters and their
even and odd parity:
39. Binary Codes
• Error-Detecting Code
– Redundancy (e.g. extra information), in the form of
extra bits, can be incorporated into binary code
words to detect and correct errors.
– A simple form of redundancy is parity, an extra bit
appended onto the code word to make the number of
1’s odd or even. Parity can detect all single-bit
errors and some multiple-bit errors.
– A code word has even parity if the number of 1’s in
the code word is even.
– A code word has odd parity if the number of 1’s in
the code word is odd.
– Example:
10001001
10001001
1
0 (odd parity)
Message B:
Message A: (even parity)