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

CHP 3 Computer Arithmetic

The document provides an overview of various number systems used in digital technology, including decimal, binary, octal, and hexadecimal systems, along with their conversions. It explains the concepts of bits, bytes, and nibbles, and details the methods for converting between different bases, including examples of binary, octal, and hexadecimal conversions. Additionally, it covers arithmetic operations in binary, octal, and hexadecimal systems, as well as the concepts of 1's and 2's complement for signed and unsigned numbers.

Uploaded by

Mohammad Shaikh
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

CHP 3 Computer Arithmetic

The document provides an overview of various number systems used in digital technology, including decimal, binary, octal, and hexadecimal systems, along with their conversions. It explains the concepts of bits, bytes, and nibbles, and details the methods for converting between different bases, including examples of binary, octal, and hexadecimal conversions. Additionally, it covers arithmetic operations in binary, octal, and hexadecimal systems, as well as the concepts of 1's and 2's complement for signed and unsigned numbers.

Uploaded by

Mohammad Shaikh
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 70

Module 3 Computer

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

 Hexadecimal System uses sixteen


symbols
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E,
F
Bits, Bytes,
Nibbles
 Bits 1001011
(b) 0
most least
significa significa
nt bit nt bit

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.5 + 0.08 + 0.001 = 0.581


Binary-to-Decimal
Conversion
 . 10 (base-
1 2)
1 X 2- = =
1 1x0.5 0.5
0 X 2-2 =
0x0.25 =0
1 X 2-3 =
1x0.125 = 0.125

0.5 + 0 + 0.125 = 0.625

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.25 + 0.017825 = 0.267825

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

 To convert binary to octal and hexadecimal number, first break the


binary number into 3- and 4-bits sections respectively starting from
LSB to MSB.
 Then convert each 3- and 4-bit section to its octal and hexadecimal
equivalent respectively.
 To convert octal and hexadecimal to binary number, first convert each
octal and hexadecimal digit to its 3-bit and 4-bit binary equivalent
respectively. Then, combine the sections to get the binary number.

Example: Determine the octal equivalent of (010111) 2.

The octal equivalent of (010111) 2 is (27)8.


Conversion Between Number Bases
(Contd.)
Converting among Binary, Octal, and
Hexadecimal Fractions
Example: Determine the octal equivalent of (.1110110) 2.

Example: Determine the binary equivalent of (2B.6C) 16.


Conversion Between Number Bases
(Contd.)
Example: Determine the hexadecimal equivalent of (2327) 8.

Combining the 3-bit binary blocks, we have 010011010111.


Separating the group of binary numbers (from left side) into
the 4-bit binary number and converting these blocks into
their respective hexadecimal symbols, we have
0100 1101 0111
4 D 7

Thus, the hexadecimal equivalent of (2327)8 is (4D7)16.


Conversion Between Number Bases
(Contd.)
Converting between Octal and Hexadecimal
Fractions
Example: Determine the octal equivalent of (4.3C) 16.
Arithmetic System
Binary Arithmetic
Binary Addition

Example: Add the binary numbers 1111 and 1010.


Arithmetic System (Contd.)
Binary Subtraction

Example: The binary difference of (1101–10110)


Arithmetic System (Contd.)
Octal Arithmetic
 Octal Addition

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.

Thus, the resultant octal sum is 7274.


Arithmetic System (Contd.)

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.

Example: Subtract (677)8 from (770)8


Arithmetic System (Contd.)

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.

Example: Add the hexadecimal numbers (A27E9)16 and (6FB43)16

Thus, the hexadecimal sum is (11232C)16.


Arithmetic System (Contd.)
Hexadecimal Subtraction
In this subtraction, 16 will be used as borrow instead of 1.

Example: Subtract (1F65)16 from (7E2CA)16

The hexadecimal difference is (7C365)16.


1s Complement
• The 1's complement of a number is found by changing all 1's to 0's and all 0's to
1's.
• This is called as taking complement or 1's complement. Example of 1's
Complement is as follows.
2s Complement

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

 An n-bit signed binary number


consists of two parts. A part
denoting the sign of the number
and a part denoting the
magnitude of the number. The
MSB is always a sign bit which
denotes the sign of the number
and the convention is that 0 and
1 denote ‘+’ and ‘–’, respectively.
gned and Unsigned Numbers (Contd.)

Negative binary numbers- 1s complement


 To form the negative of any number, first complement all the bits of
the number.
 This result is known as the one’s complement of the original
number.
 This requires us to change every logic 1 bit in a number to logic 0,
and every logic 0 bit to a logic 1.
 For instance, the 1s complement of 0011 0110 will be 11001001.
Negative binary numbers-2s complement
 To obtain the 2s complement of a number, there is a two-
step process:
 Take the 1s complement of the number by changing every logic 1
bit in the number to logic 0 bit, and change every logic 0 bit to logic
1 bit.
 Add 1 to the 1s complement of the binary number.
 Now, we have the 2s complement of the original number. Here, we
can notice that the MSB has become 1.
 For instance, the 2s complement of 00110110 will be 11001010.
Addition using 1's complement

Using one’s complement we can add two negative numbers and also a negative
number with a positive number.

• 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
Step 1: We first find the one’s complement of the negative number by replacing 1
with 0 and 0 with 1.
Step 2: Once the one’s complement is found then, we add the positive number to the
one’s complement of the negative number.
Step 3: After addition, the end-around carry of the sum is added to the result for the
final answer.
Addition using 1's complement

Example: Add (1010)2 and (−1001)2.

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

When the Negative Number is Greater


• Step 1: We will first find the 1’s complement of the negative number and then
• Step 2: Add the positive number with the 1’s complement of the negative number.
• Step 3: Now, in this case, there will be no end-around carry. So, we will find the final
result by taking the 1’s complement of the result after addition.
• Example: Add (0111)2 and (−1000)2

• 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 Two Negative Binary Numbers


• First, we will represent both the numbers in a 5-bit register. This can be done by
adding the required number of zeroes on the left of the number.
• Once the numbers are recorded in 5-bit, we find the 1’s complement of both the
numbers by replacing 0 with 1 and 1 with 0.
• The next step includes the addition of 1’s complement of both the numbers.
• Next, we will add the end-around carry to the rest of the number.
• 1’s complement of the number so obtained is found and the final result is written
with a negative sign along the 1’s complement last obtained.
Addition using 1's complement
Example: Add (−1010)2 and (−0101)2 .
Solution:
• First we represent the given numbers in the 5-bit register. So, the numbers become
01010 and 00101.
• The next step includes finding the 1’s complement of both the numbers. The 1’s
complement of 01010 is 10101 and that of 00101 is 11010.
• Adding the 1’s complement, we get:

• 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.

The final answer is -1000.


Subtraction by 1’s
Complement
To perform binary subtraction using 1’s complement, please follow the steps given
below:
Step 1: Determine the 1’s complement of the subtrahend (which means the second
number of subtraction).
Step 2: Add it with the minuend or the first number.
Step 3: If there is a carryover left, then add it with the result obtained from step 2.
Step 4: If there are no carryovers, then the result obtained in step 2 is the difference
of the two numbers using 1’s complement binary subtraction.
For example, Subtract 110010–100101 using 1’s complement.
Here the decimal equivalent of 110010 is 50 and 100101 is 37.
Step 1: 1’s complement of 100101 is 011010
Step 2: Add this with 110010
Step 3: Arrange the numbers as given below and add them.

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.

For example, Subtract 10101–00111 using 2’s complement.


Here the decimal equivalent of 10101 is 21 and 00111 is 7
Step 1: 2’s complement of 00111 is 11001
Step 2: Add this with 10101.

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

1. Add the binary numbers 0111 and -1000 using 1s complement.


2. Find the sum of the following by using 2’s complement:
(i) -1011 and -0101
(ii) + 0111 and – 0011.
(iii) + 0 0 1 1 and - 0 1 0 1
(iv) + 0 1 0 0 and - 0 1 1 1
(v) – 0011 and – 0101
(vi) -0111 and – 0010.
Exercise 5

1. Subtract the following:

i. 101 from 1001 (1s complement)


ii. 111 from 1000 (1s complement)
iii. 10110 – 11010 (2s complement)
iv. 10110-01111 (2s complement)
v. Subtract 110101–100010 using 1’s complement.
vi. Subtract (1010) from (1111) using 2's complement method.
vii. Subtract (1010)2(1010)2 from (1000)2(1000)2 using 2's complement.

You might also like