Chapter Four - Number Systems 2 N

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

CHAPTER FOUR: NUMBER SYSTEMS 2

Binary Arithmetic
Binary arithmetic is essential part of all the digital computers and many other digital system.
Binary Addition
It is a key for binary subtraction, multiplication, division. There are four rules of binary addition.

In fourth case, a binary addition is creating a sum of (1 + 1 = 10) i.e. 0 is written in the given
column and a carry of 1 over to the next column.
Example – Addition

Binary Subtraction
Subtraction and Borrow, these two words will be used very frequently for the binary subtraction.
There are four rules of binary subtraction.

Example
Binary Multiplication
Binary multiplication is similar to decimal multiplication. It is simpler than decimal
multiplication because only 0s and 1s are involved. There are four rules of binary multiplication.

Binary Division
Binary division is similar to decimal division. It is called as the long division procedure.
CASE A/B Division
1 0/0 Meaningless
2 0/1 0
3 1/0 Meaningless
4 1/1 1
Similar to the decimal number system, the binary division is similar, which follows the four-step
process:
i. Divide
ii. Multiply
iii. Subtract
iv. Bring down
Example

1’S AND 2’S COMPLIMENT


Complements
In order to perform the logical manipulation and to simplify the subtraction operation, the digital
systems generally use complements. The binary number system contains two types of
complements, i.e., 1's complement and 2's complement.
1's Complement
The binary numbers can be easily converted into the 1's complement with the help of a simple
algorithm. According to this algorithm, if we toggle or invert all bits of a binary number, the
generated binary number will become the 1's complement of that binary number. That means we
have to transform 1 bit into the 0 bit and 0 bit into the 1 bit in the 1's complement. N' is used to
indicate the 1's complement of a number.
Example
1's complement of binary number 5 (0101) is binary number 10 (1010)
1's complement of binary number 13 (1101) is binary number 2 (0010)
There is another way to find the 1's complement of a number. We can use a formula to find it,
which is described as follows:
N' = (2n - 1) – N
N' is used to show the -N in 1's complement notation

N is used to show the positive integer


n is used to show the number of bits per word
Example:
Suppose we have 8 bit word, and N = 6. Now the 1's complement of N is described as follows:
N' = (28 - 1) - 6
= 249
= (11111001)2
2’S COMPLIMENT
The binary numbers can also be easily converted into the 2's complement with the help of a very
simple algorithm. According to this algorithm, we can get the 2's complement of a binary
number by first inverting the given number. After that, we have to add 1 into the LSB (least
significant bit). That means we have to first perform 1's complement of a number, and then we
have to add 1 into that number to get the 2's complement. N* is used to show the 2's complement
of a number.

Example

1. 2's complement of binary number 5 (0101) is binary number 11 (1011)

2. 1's complement of binary number 13 (1101) is binary number 3 (0011)

There is another way to find the 2's complement of a number. We can use a formula to find it,
which is described as follows:

N* = 2n - N

Where

N* is used to show the -N in 1's complement notation

N is used to show the positive integer


n is used to show the number of bits per word

There are various uses of 2’s complement of Binary numbers, mainly in signed Binary number
representation and various arithmetic operations for Binary numbers, e.g., additions,
subtractions, etc. Since 2’s complement representation is unambiguous, so it very useful in
Computer number representation.

2’s Complementation in Signed Binary number Representation

Positive numbers are simply represented as simple Binary representation. But if the number is
negative then it is represented using 2’s complement. First represent the number with positive
sign and then take 2’s complement of that number.

Example − Let we are using 5 bits registers. The representation of -5 and +5 will be as follows:

+5 is represented as it is represented in sign magnitude method. -5 is represented using the


following steps:

 +5 = 0 0101
 Take 2’s complement of 0 0101 and that is 1 1011. MSB is 1 which indicates that
number is negative.

MSB is always 1 in case of negative numbers.

Range of Numbers −For k bits register, positive largest number that can be stored is (2 (k-1)-1)
and negative lowest number that can be stored is -(2(k-1)).
The advantage of this system is that 0 has only one representation for -0 and +0. Zero (0) is
considered as always positive (sign bit is 0) in 2’s complement representation. Therefore, it is
unique or unambiguous representation.

Arithmetic operations using 2’s Compliment

Subtractions by 2’s Complement

The algorithm to subtract two binary numbers using 2’s complement is explained as below −

 Take 2’s complement of the subtrahend


 Add with minuend
 If the result of above addition has carry bit 1, then it is dropped and this result will be
positive number.
 If there is no carry bit 1, then take 2’s complement of the result which will be negative

Note that subtrahend is number that to be subtracted from another number, i.e., minuend.

Also, note that adding end-around carry-bit occurs only in 1’s complement arithmetic operations
but not 2’s complement arithmetic operations.

Example 1 (Case-1: When Carry bit 1) −Evaluate 10101 - 00101

According to above algorithm, take 2’s complement of subtrahend 00101, which will be

11011, then add both of these. So, 10101 + 11011 =1 10000. Since, there is carry bit 1,

so dropped this carry bit 1, and take this result will be 10000 will be positive number.

Example 2 (Case-2: When no Carry bit) −Evaluate 11001 - 11100

According to above algorithm, take 2’s complement of subtrahend 11110, which will be
00100. Then add both of these, So, 11001 + 00100 =11101. Since there is no carry bit

1, so take 2’s complement of above result, which will be 00011, and this is negative number, i.e,
00011, which is the answer.

Addition using 2’s Compliment

Case-1 − Addition of positive and negative number when positive number has greater
magnitude:

When positive number has greater magnitude, then take simply 2’s complement of negative
number and carry bit 1 is dropped and this result will be positive number.

Example −Add 1110 and -1101.

So, take 2’s complement of 1101, which will be 0011, then add with given number. So,
1110+0011=1 0001, and carry bit 1 is dropped and this result will be positive number, i.e.,
+0001.

Note that if the register size is big then use sign extension method of MSB bit to preserve sign of
number.

Case-2 − Addition of positive and negative number when negative number has greater
magnitude

When the negative number has greater magnitude, then take 2’s complement of negative number
and add with given positive number. Since there will not be any endaround carry bit, so take 2’s
complement of the result and this result will be negative.

Example −Add 1010 and -1100 in five-bit registers.

Note that there are five-bit registers, so these new numbers will have 01010 and -01100. Now
take 2’s complement of 01100 which will be 10100 and add 01010+10100=11110. Then take 2’s
complement of this result, which will be 00010 and this will be negative number, i.e., -00010,
which is the answer.

Case-3 − Addition of two negative numbers


You need to take 2’s complement for both numbers, then add these 2’s complement of numbers.
Since there will always be end-around carry bit, so it is dropped. Now, take 2’s complement also
of previous result, so this will be negative number.

Alternatively, you can add both of these Binary numbers and take result which will be negative
only.

Example − add -1010 and -0101 in five bit-register.

These five bit numbers are -01010 and -00101. Add 2’s complements of these numbers,
10110+11011 =1 10001. Since, there is a carry bit 1, so it is dropped. Now take the 2’s
complement of this result, which will be 01111 and this number is negative, i.e, -01111, which is
answer.

Note that 2’s complement arithmetic operations are much easier than 1’s complement because
there is no addition of end-around-carry-bit.

Disadvantage of 2’s Compliment

 2's complement notation is not very simple to understand because it is very much
different from the conventional way of representing signed numbers.

Advantages

 There is a single notation for zero, which is very convenient when the computer wants to
test for a 0 result.
 It is very convenient for the computer to perform arithmetic. The addition operation
straightaway gives the correct result.

Hence, 2's complement notation is generally used to represent signed numbers inside a computer.

FLOATING POINT FORMATS

Why floating-point numbers are needed

Since computer memory is limited, you cannot store numbers with infinite precision, no matter
whether you use binary fractions or decimal ones: at some point you have to cut off. But how
much accuracy is needed? And where is it needed? How many integer digits and how many
fraction digits?

To an engineer building a highway, it does not matter whether it’s 10 meters or 10.0001 meters
wide - their measurements are probably not that accurate in the first place. To someone designing
a microchip, 0.0001 meters (a tenth of a millimeter) is a huge difference - But they’ll never have
to deal with a distance larger than 0.1 meters. A physicist needs to use the speed of light (about
300000000) and Newton’s gravitational constant (about 0.0000000000667) together in the same
calculation.

To satisfy the engineer and the chip designer, a number format has to provide accuracy for
numbers at very different magnitudes. However, only relative accuracy is needed. To satisfy the
physicist, it must be possible to do calculations that involve numbers with different magnitudes.

Basically, having a fixed number of integer and fractional digits is not useful - and the solution is
a format with a floating point.

How floating-point numbers work

The idea is to compose a number of two main parts:

 A significand that contains the number’s digits. Negative significands represent negative
numbers.
 An exponent that says where the decimal (or binary) point is placed relative to the
beginning of the significand. Negative exponents represent numbers that are very small
(i.e. close to zero).

Such a format satisfies all the requirements:

 It can represent numbers at wildly different magnitudes (limited by the length of the
exponent)
 It provides the same relative accuracy at all magnitudes (limited by the length of the
significand)
 It allows calculations across magnitudes: multiplying a very large and a very small
number preserves the accuracy of both in the result.
Decimal floating-point numbers usually take the form of scientific notation with an explicit point
always between the 1st and 2nd digits. The exponent is either written explicitly including the
base, or an e is used to separate it from the significand.

The standard

Nearly all hardware and programming languages use floating-point numbers in the same binary
formats, which are defined in the IEEE 754 standard. The usual formats are 32 or 64 bits in total
length.

Note that there are some peculiarities:

 The actual bit sequence is the sign bit first, followed by the exponent and finally the
significand bits.
 The exponent does not have a sign; instead an exponent bias is subtracted from it (127 for
single and 1023 for double precision). This, and the bit sequence, allows floating-point
numbers to be compared and sorted correctly even when interpreting them as integers.

Decimal to Floating Point Conversion


To convert a decimal number to binary floating point representation:
i. Convert the absolute value of the decimal number to a binary integer plus a binary
fraction.
ii. Normalize the number in binary scientific notation to obtain m and e.
iii. Set s=0 for a positive number and s=1 for a negative number.
To convert 22.625 to binary floating point:

i. Convert decimal 22 to binary 10110. Convert decimal 0.625 to binary 0.101.


Combine integer and fraction to obtain binary 10110.101.
ii. Normalize binary 10110.101 to obtain 1.0110101 2 *24 Thus, m = 1.01101012 and e =
4.
iii. The number is positive, so s=0.
Also have a look at https://www.youtube.com/watch?v=RuKkePyo9zk&t=71s video and more.

You might also like