CHP 3 Computer Arithmetic
CHP 3 Computer Arithmetic
Arithmetic
NUMBER SYSTEM &
CONVERSION
Number
System
Introducti
on
Many number systems are in use in
digital technology. The most
common are :
🞑
🞑 Decimal(Base
(Base 10)
Binary 2)
🞑 Octal
(Base (Base 16)
🞑 Hexadecimal
8)
The decimal system is the number system
that we use everyday
Number
System
Decimal system uses 10 symbols
(digits)
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Octal System uses eight symbols
0, 1, 2, 3, 4, 5, 6, 7
Binary System uses only two
symbols
0 and 1
byt
Bytes & e
Nibbles 1001011
🞑Byte (B) = 8 0 nibbl
e
bits
Used everyday CEBF9AD
🞑 Nibble (N) = 4 7
most
significa
least
significa
bits nt byte nt byte
Not commonly
Decimal
System
The decimal system is composed of 10
numerals or symbols. These 10 symbols are
0,1,2,3,4,5,6,7,8,9; using these symbols as
digits of a number, we can express any
quantity.
Example : 3501.51
3 5 0 1 . 5 1
digi
Most t Least
Significant decimal Significant
Digit point Digit
Binary
System
The binary system is composed of 2
numerals or symbols 0 and 1; using these
symbols as digits of a number, we can
express any quantity.
Example : 1101.01
1 1 0 1 . 0 1
bi
Most t Least
Significant Bit binary Significant
point Bit
Decimal Number
Quantity (positional
number)(base-
3 5 0
1 10)
1 X 100 1
=
0 X
101
= 0
5 X
102
=
Binary-to-Decimal
Conversion
110 (base-
1 2)
1 = 1
X = 0
= 4
20
= 8
0
X
Octal-to-Decimal
Conversion
521 (base-
7 8)
7 = 7x1 =X 870
1 = 1x8 =X 881
2 = 2x6 =X 128
82
4
5 X 83
= 5x512 = 2560
2560 + 128 + 8 + 7 = 2703
52178 = 270310
Hexadecimal-to-Decimal
Conversion
1AC (base- [ A = 10, B = 11, C = 12, D = 13, E =
14, F = 15 ]
F 16)
15
15 X 16 =15x1 =
0
12 X 161 =
=12x16 192
10 X 1632 =
1 X 16 =
=10x256 2560
5x4096 =
20480
20480 + 2560 +192 + 15 = 23247
Decimal Number
Quantity (fractional
number)(base-
. 5 8
1 10)
5 X 10- = =
1 5x0.1 0.5
8 X 10-2 =
8x0.01 = 0.08
1 X 10-3 =
1x0.001 = 0.001
0.1012 = 0.62510
Octal-to-Decimal
Conversion
. 2 (base-
5 8)
2 X 8- = =
1 2x0.125 0.25
5 X 8-2 =
5x0.015625 =
0.017825
0.258 = 0.26782510
Hexadecimal-to-Decimal
Conversion
. F (base-
5 16)
15 X16- = 15x0.0625
1
0.9375 = =
=5 0.01953125
X16-2 5x0.00390625
0.9375 + 0.01953125 =
0.95703125
0.F516 = 0.9570312510
Exercise
1
Convert these binary system numbers to
decimal system numbers
a) 100101101
b)
11100.1001
c)111111
d)100000.01
11
b)
1x24 + 1x23 +
1x22 + 0x21 +
0x20 + 1x2-1 +
0x2-2 + 0x2-3 1+
1x2-4
Decimal-to-Binary Conversion
(positional number)
250 25010 = 1 1 1 1 1 0
2 1 02
Remainder 0
250
2 Remainder 1
2 62
2 Remainder 0
31
2 Remainder 1
125
15
2 Remainder 1
7 Remainder 1
2
2 1 Remainder 1
3 0
Decimal-to-Octal
Conversion
25
0 8
250 3 Remainder 2
8 1 3 7
Remainder
25010 =
3728
Decimal-to-Hexadecimal
Conversion
250
16
1 Remaind 1
250 5 er 0
25010 = 151016
?
=
FA16
Decimal-to-Binary Conversion
(fractional number)
0.
4375
0.4375 x 2 = 0.875
0
0.8750 x 2 = 1.75
0.75 x 2 = 1.5
0.5 x2 = 1.0
0.437510 = 0.01112
Decimal-to-Octal
Conversion
0.
4375
0.4375 x 8 = 3.5
0.5 x8 = 4.0
0.437510 = 0.348
Decimal-to-Hexadecimal
Conversion
0 . 4375
0.4375 x =
16 7.0
0.437510 = 0.716
Exercise
2
Convert these c) (22.5)10=(
decimal system ? )2
numbers to binary 22 22
11
system numbers
2 50
a)12
2 21
7
b)38 1
c)22. 0
5
d) 0.5
764. x2
Base X – to – Base Y
Conversion
We can convert base x number to base y
number by following these steps :
🞑 Convert base x to base 10 (decimal system
number)
🞑 Then, convert decimal number to base y
Exampl
e
Convert to hexadecimal system
372.34 8 372.348number
🞑 Convert to decimal system
number
372.348 = . (3x8-1) +
(3x82)+(7x81)+(2x80) (4x8-2)
= 192 + . 0.375 +
56 + 2 0.0625
🞑 Convert 250.437510 to hexadecimal system
= 250 .
number
250.4375 4375
10
250 / Positional
16 = 15number
remainder 0.4375 * 16 = 7.0
Fractional number 10 0.4375 0.716
250 FA16
372.348 = FA.716
Exercise 3
(TODO)
Convert these numbers to octal system
number
🞑 11100.10012
🞑 1111112
🞑 5A.B16
Convert these numbers to binary
system number
🞑 5A.B16
🞑 75.28
Converting among Binary, Octal, and
Hexadecimal
1. First, add the two digits of the unit column of the octal number in
decimal.
2. During the process of addition, if the sum is less than or equal to
7, then it can be directly written as a octal digit.
3. If the sum is greater than 7, then subtract 8 from that particular
digit and carry 1 to the next digit position.
Example: Add the octal numbers 5647 and 1425.
Octal Subtraction
During octal subtraction, instead of 1, we will borrow 8 and the
rest of the steps are similar to that of binary subtraction.
Hexadecimal Arithmetic
Hexadecimal Addition
1. First add the unit column of the hexadecimal digits in decimal.
2. During the process of addition, observe if the sum is 15 or less,
then it can be directly expressed as a hexadecimal digit.
3. If the sum is greater than 15, then subtract 16 from that
particular digit and carry 1 to the next digit position.
The 2's complement of binary number is obtained by adding 1 to the Least Significant Bit
(LSB) of 1's complement of the number.
2's complement = 1's complement + 1
Signed and Unsigned Numbers
Using one’s complement we can add two negative numbers and also a negative
number with a positive number.
Solution: The first step is to find the 1’s complement of the negative number that is (-1001).
The 1’s complement is 0110. Now we will add, 1010 and 0110.
Here the end-around carry is 1. So, we add 1 to the rest of the result that means adding 0000 +
1 = 0001
So, 0001 is the answer when we add 1010 and -1001.
Addition using 1's complement
• Solution: The first step is to find the 1’s complement of the negative number by replacing
0 with 1 and 1 with 0. So, the 1’s complement of -1000 is 0111. Now, we will add 0111
and 0111.
• And now, we will find the 1’s complement of 1110, that is 0001. So, the result of addition
of 0111 and -1000 is 0001.
Addition using 1's complement
• Adding the end-around carry to the rest of the result, we get, 01111 + 1 =
10000.
• We now find the 1’s complement of 10000, i.e. 01111.
• The final answer upon addition of -1010 and -0101 is -01111.
Binary Addition Using 2’s
Complement
Adding a Positive Number to a Negative Number.
There can be two cases in such addition, either the positive number can be greater than
the negative number or vice versa.
Case 1: When the Positive Number is Greater
1. In order to add a positive number to a negative number when the positive number is
greater, we first represent both the numbers in the 5-bit register.
2. Once represented, we find the 2’s complement of the negative number.
3. We will now add the positive number and the 2’s complement of the negative number.
4. The end-around carry is generated after addition is discarded and the remaining terms
are the result of addition.
Example: Add 1011 and -0101.
Solution: The first step is to represent both the numbers in the 5-bit register that is 01011
and 00101.
Now, we have to find the 2’s complement of the second number that is 00101. For this the
1’s complement of the number is 11010 and then we add 1 to the 1’s complement. That is
11010+1 = 11011.
We now add the positive number and the 2’s complement of the negative number:
The end-around carry 1 is discarded and the remaining numbers are the final result after
addition.
So, 1011 + (-0101) = 0110
Case 2: When the Negative number is Greater
1. When the negative number is greater than the positive number we first represent
both the numbers in the 5-bit register.
2. After representing, we find the 2’s complement of the negative number.
3. This 2’s complement is then added to the positive number.
4. The end-around carry in this case is discarded and the 2’s complement of the
remaining number is computed to get the final result with a negative sign.
Let us understand this with an example:
Example: Add 0100 and –0111
Solution:
1. We first represent the numbers in a 5-bit register that is 00100 and 00111.
2. Now, we find the 2’s complement of 00111. That is finding 1’s complement and then
adding 1 to the number. So, 2’s complement of 00111 is 11001.
3. We now add the positive number and the 2’s complement of the negative number, that
is 00100 + 11001, we get
The end-around carry is discarded and the remaining number is 1101. We now find the 2’s
complement of 1101 that is 0010 + 1 = 0011.
So, the final answer is -0011
When Both the Numbers are Negative
When both the numbers are negative, we have to follow a series of steps.
1. Firstly, we need to represent the number in the 5-bit register and then find the 2’s
complement of both the numbers.
2. After finding the 2’s complement, we need to add the numbers obtained and discard
the end-around carry in the sum.
3. We then find the 2’s complement of the resulting number and represent the final
answer with a negative sign.
Example: Add -0011 and -0101
Solution: We will first represent the two numbers in a 5-bit register, that is the given
numbers become 00011 and 00101.
Now, we find the 2’s complement of 00011, i.e. 11100 + 1 = 11101 and 00101, i.e. 11010 + 1
= 11011.
We now add the 2’s complement of both the numbers, that is:
We, discard the end-around carry and find the 2’s complement of the remaining term that is
11000.
The 2’s complement of 11000 is 00111 + 1 = 01000.
Step 4: So, the leftmost digit 1 is a carryover of this addition. Since there is a carryover we
add it with the result, which is 001100.
Therefore, the answer is 1101. And the difference of 50–37=13.The decimal equivalent of
1101 is 13.So, the answer is verified.
Binary subtraction Using 2’s
Complement
To perform binary subtraction using 2’s complement, please follow the steps given below:
Step 1: In the first step, find the 2’s complement of the subtrahend.
Step 2: Add the complement number with the minuend.
Step 3: If we get the carry by adding both the numbers, then we discard this carry and the
result is positive, else take 2’s complement of the result which will be negative.
Step 3: We get the carry bit 1. So we discard this carry bit and remaining is the final result and a
positive number. Therefore the answer is 1110.
Since the difference of 21–7=14.
The decimal equivalent of 1110 is 14.
So, the answer is verified.
Exercise 4