Chapter Four - Number Systems 2 N
Chapter Four - Number Systems 2 N
Chapter Four - Number Systems 2 N
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
Example
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
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.
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 = 0 0101
Take 2’s complement of 0 0101 and that is 1 1011. MSB is 1 which indicates that
number is negative.
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.
The algorithm to subtract two binary numbers using 2’s complement is explained as below −
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.
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.
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.
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.
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.
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.
Alternatively, you can add both of these Binary numbers and take result which will be negative
only.
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.
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.
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.
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).
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.
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.