02 Digital Arithmetic
02 Digital Arithmetic
Digital
Arithmetic
CPE107-4 Logic Circuits and Design
Engr. John Paul T. Cruz
Internal Use
Objectives
• Differentiate unsigned and signed representations of binary numbers.
• Understand the concept of signed numbers.
• Represent numbers in unsigned and signed representations.
• Perform digital arithmetic operations on unsigned and signed numbers.
• Perform addition and subtraction of BCD and Hexadecimal Numbers
Internal Use
The binary arithmetic operations always start from the least significant bit. These operations
can be done on unsigned and signed numbers. Unsigned numbers are, by definition,
positive numbers and do not require an arithmetic sign.
Internal Use
Binary Addition
There are four basic rules in order to perform binary addition. These rules are listed below:
Notice that the first three rules are quite simple since there is no difference between these
binary rules and the corresponding decimal rules. The fourth rule, however, is different from
decimal. Whenever we add two 1s together in binary, we generate a carry to the next
column since the binary system only has two digits.
Internal Use
Binary Addition
1 0 02
1 1 0.0 1 02
+ 0 0 1.0 1 12
1 1 1.1 0 12
Internal Use
Binary Subtraction
There are four basic rules in order to perform binary subtraction. These rules are listed
below:
Rules 1, 3, and 4 are similar to their decimal counterparts. The second rule, however, uses
the concept of borrowing from another column.
Internal Use
Binary Subtraction
1 1
0 1 0 1 0 0 1 2
1 0 1 0 1.1 0 12
- 0 1 0 1 1.1 1 02
1 0 0 1.1 1 12
Internal Use
Binary Multiplication
Binary multiplication uses the same technique as decimal multiplication. In fact, binary
multiplication is easier because each digit we multiply is either zero or one.
In Binary multiplication, there will be partial products which will be added to obtain the
complete product.
Internal Use
Binary Multiplication
1 0 1 1.0 12
x 1 1 0.12
1 0 1 1 0 12
0 0 0 0 0 0 02
101101 2
101101 2
1 0 0 1 0 0 1.0 0 12
Internal Use
Binary Division
In Binary division, we use the same long division technique in the decimal system.
Binary Division
1 0.12
1 0 1 0 1.02
10 2
0 1 02
1 02
02
Internal Use
The most significant bit of a binary number represents the sign bit. The signed binary
number is positive if the sign bit is equal to zero. Otherwise, it is negative. There are three
ways to represent signed numbers:
Sign Extension
Modern digital systems store numbers in even multiples of 4 bits (4, 8, 12, 16, 20, etc.) In a
system that stores 8-bit numbers, the 7-bits represent the magnitude, and the MSB
represents the sign.
For instance, if we need to store a positive 5-bit number in an 8-bit storage location, we
extend the sign.
The same principle is applied if the number is negative. For instance, if we store a negative
6-bit number in an 8-bit storage location:
Arithmetic Overflow
An Arithmetic Overflow occurs when there are insufficient bits in a binary number
representation to portray the result of the arithmetic operation. This condition can only occur
when adding two positive or two negative numbers.
An overflow condition can be detected by checking if the sign bit of the result is the same as
the sign bits of the numbers being added.
Internal Use
The BCD code does not use 1010, 1011, 1100, 1101, 1110, 1111. In other words, only 10 of
the 16 possible 4-bit binary code groups are used. The radix is BCD (i.e. 100001110100BCD)
Internal Use
BCD Addition
In performing BCD addition, there are two cases to consider: sum is less than or equal to 9,
or sum is greater than 9.
The BCD codes are added using the principle of Binary addition. Since none of the sums
exceed 9, no carries are produced to the next code.
Internal Use
BCD Addition
The BCD codes are added using the principle of Binary addition. Since none of the sums
exceed 9, no carries are produced to the next code.
Internal Use
BCD Subtraction
In performing BCD subtraction, the 9’s complement of the subtrahend must be obtained.
The 9’s complement of any decimal number is obtained by the formula 9 – N, where N is
the Decimal number.
BCD Subtraction
1 1 1
1510 = 0001 0101BCD
- 410 = 1001
1 1
0101
1 1 1 BCD
1110 1 1010 1010
0110 0110
Consider the fact that 410 can be
0001 0000
represented by 0410 when being
added to a 2-digit augend. Obtain the
1
9’s complement of 0 as well. 0001 0001BCD
Internal Use
BCD Subtraction
1 1 1
2310 = 0010 0011BCD
-7210 = 00101 0111
1 1 BCD
-4910 0100 1010
0110
0101 0000
0100 1001BCD
Internal Use
Hexadecimal Addition
The addition of Hexadecimal numbers is done in much the same way as decimal addition if
you remember the hex digit representations of 10-15. The procedure is as follows:
1. Add the two hex digits in decimal, mentally inserting the decimal equivalent for those
digits larger than 9 (A-F).
2. If the sum is less than or equal to 15, it can be directly expressed as a Hex digit.
3. If the sum is greater than or equal to 16, subtract 16 and carry a 1 to the next digit
position.
Internal Use
Hexadecimal Addition
2A3916 3 A F16
9 + 5 = 14 or E
+ 1B516 3 + B = 14 or E + 2 3 C16
A + 1 = 11 or B
2BEE16 5 14 27
-16
Since 27 > 16, subtract 16 to
get 11, which hexadecimal B
11
and carry a 1 to the next
position.
5 E B16
Internal Use
Hexadecimal Subtraction
The process is similar to binary subtraction, but you will borrow 16 from the next digit
instead.
16 16
5 B A16
- 1 F C16
3 B E16
Internal Use