2.1. Binary Addition
Binary addition involves adding of two or more binary numbers.
The binary addition rules are used while performing the binary addition.
Table 1 shows the binary addition rules.
Table 1. Binary Addition Rules for two inputs
Binary addition of three inputs, when all the inputs are 1,
follows the rule shown in Table 2.
Table 2. Binary Addition Rules for three inputs
Addition of the binary numbers involves the following steps-
- Start addition by adding the bits in unit column (the rightmost column).
Use the rules of binary addition.
- The result of adding bits of a column is a sum with or without a carry.
- Write the sum in the result of that column.
- If carry is present, the carry is carried-over to the addition of the next left column.
- Repeat steps 2-4 for each column, i.e., the tens column, hundreds column and so on.
Let us now understand binary addition with the help of some examples.
Example 1. Add 10 and 01. Verify the answer with the help of decimal addition.
When we add 0 and 1 in the unit column, sum is 1 and there is no carry.
The sum 1 is written in the unit column of the result.
In the tens column, we add 1 and 0 to get the sum 1. There is no carry.
The sum 1 is written in the tens column of the result.
Example 2.
Add 01 and 11.
Verify the answer with the help of decimal addition.
When we add 1 and 1 in the unit column, sum is 0 and carry is 1.
The sum 0 is written in the unit column of the result.
The carry is carried-over to the next column, i.e. the tens column.
In the tens column, we add 0, 1 and the carried-over 1, to get sum 0 and carry 1.
The sum 0 is written in the tens column of the result.
The carry 1 is carried-over to the hundreds column.
In the hundreds column, the result is 1.
Example 3. Add 11 and 11. Verify the answer with the help of decimal addition.
When we add 1 and 1 in the unit column, sum is 0 and carry is 1.
The sum 0 is written in the unit column of the result. The carry is carried-over to the tens column.
In the tens column, we add 1, 1 and the carried-over 1.
We use the rule for binary addition of three inputs shown in Table 2. We get sum 1 and carry 1.
The sum 1 is written in the tens column of the result.
The carry 1 is carried-over to the hundreds column.
In the hundreds column, the result is 1.
Example 4. Add 1101 and 1111. Verify the answer with the help of decimal addition.
Example 5. Add 10111, 11100 and 11. Verify the answer with the help of decimal addition.
2.2. Binary Subtraction
Binary subtraction involves subtracting of two binary numbers.
The binary subtraction rules are used while performing the binary subtraction.
The binary subtraction rules are shown in Table 3.
The steps for performing subtraction of the binary numbers are as follows-
- Start subtraction by subtracting the bit in the lower row from the upper row, in the unit column.
- Use the binary subtraction rules. If the bit in the upper row is less than lower row,
borrow 1 from the upper row of the next column (on the left side).
The result of subtracting two bits is the difference.
- Write the difference in the result of that column.
- Repeat step 2-3 for each column, i.e., the tens column, hundreds column and so on.
Let us now understand binary subtraction with the help of some examples.
Example 1. Subtract 01 from 11. Verify the answer with the help of decimal subtraction.
When we subtract 1 from 1 in the unit column, the difference is 0.
Write the difference in the unit column of the result.
In the tens column, subtract 0 from 1 to get the difference 1.
Write the difference in the tens column of the result.
Example 2. Subtract 01 from 10.
Verify the answer with the help of decimal subtraction.
When we subtract 1 from 0 in the unit column, we have to borrow 1 from the left column since 0 is
less than 1. After borrowing from the left column, 0 in the unit column becomes 10,
and, 1 in the left column becomes 0. We perform 10-1 to get the difference 1.
We write the difference in the unit column of the result. In the tens column,
subtract 0 from 0 to get the difference 0.
We write the difference 0 in the tens column of the result.
Example 3. Subtract 0111 from 1110.
Verify the answer with the help of decimal subtraction.
When we do 0-1 in the unit column, we have to borrow 1 from the left column since 0 is less than 1.
After borrowing from the left column, 0 in the unit column becomes 10, and,
1 in the left column becomes 0. We perform 10-1 to get the difference 1.
We write the difference in the unit column of the result. In the tens column,
when we do 0-1, we again borrow 1 from the left column.
We perform 10-1 to get the difference 1. We write the difference in the tens column of the result.
In the hundreds column, when we do 0-1, we again borrow 1 from the left column.
We perform 10-1 to get the difference 1.
We write the difference in the hundreds column of the result.
In the thousands column, 0-0 is 0. We write the difference 0 in the thousands column of the result.
Example 4. Subtract 10010 from 10101. Verify the answer with the help of decimal subtraction.
Example 5. Subtract 101111 from 110001. Verify the answer with the help of decimal subtraction.
3. Signed and Unsigned Numbers
A binary number may be positive or negative.
Generally, we use the symbol “+” and “-” to represent positive and
negative numbers, respectively. The sign of a binary number has to be
represented using 0 and 1, in the computer.
An n-bit signed binary number consists of two parts –
sign bit and magnitude.
The left most bit, also called the Most Significant Bit (MSB) is the
sign bit.
The remaining n-1 bits denote the magnitude of the number.
In signed binary numbers, the sign bit is 0 for a positive number
and 1 for a negative number.
For example, 01100011 is a positive number since its sign bit is 0, and, 11001011
is a negative number since its sign bit is 1. An 8-bit signed number can represent
data in the range -128 to +127 (-2^{7} to +2^{7}-1). The leftmost bit is the sign bit.
In an n-bit unsigned binary number, the magnitude of the number n is stored in n bits.
An 8-bit unsigned number can represent data in the range 0 to 255 (2^{8}= 256).
The integer binary signed number is represented as follows –
- For a positive integer binary number, the sign bit is 0 and the magnitude is a positive binary number.
- For a negative integer binary number, the sign bit is 1.
The magnitude is represented in any one of the three ways-
- Signed Magnitude representation - The magnitude is the positive binary number itself.
- Signed 1’s complement representation - The magnitude is the 1’s complement of the positive binary number.
- Signed 2’s complement representation - The magnitude is the 2’s complement of the positive binary number.
Table 4 shows the representation of the signed number 18.
Signed magnitude and signed 1’s complement representation are seldom used in computer arithmetic.
Let’s now perform arithmetic operations on the signed binary numbers.
We use the signed 2’s complement representation to represent the negative numbers.
- Addition of signed binary numbers – The addition of any two signed binary numbers is performed as follows -
- Represent the positive number in binary form.(For e.g., +5 is 0000 0101 and +10 is 0000 1010)
- Represent the negative number in 2’s complement form. (For e.g., -5 is 1111 1011 and -10 is 1111 0110)
- Add the bits of the two signed binary numbers.
- Ignore any carry out from the sign bit position.
Please note that the negative output is automatically in the 2’s complement form.
We get the decimal equivalent of the negative output number, by finding its 2’s complement, and attaching a negative sign to the obtained result.
Let’s understand the addition of two signed binary numbers with the help of some examples.
Example 1. Add +5 and +10.
We represent +5 in binary form, i.e., 0000 0101. We represent +10 in binary form, i.e., 0000 1010.
Add the two numbers. The result is 0000 1111 i.e. +15.
Example 2. Add -5 and +10.
We represent -5 in 2’s complement form, i.e., 1111 1011. We represent +10 in binary form, i.e., 0000 1010. Add the two numbers. The result is 0000 0101 i.e. +5.
Example 3. Add +5 and -10.
We represent +5 in binary form, i.e., 0000 0101.
We represent -10 in 2’s complement form, i.e., 1111 0110.
Add the two numbers. The result is 1111 1011. The result is in 2’s complement form.
To find the decimal equivalent of the result 1111 1011 –
Find the 2’s complement of 1111 1011, i.e., 0000 0100 + 1 = 0000 0101. This is binary equivalent of +5. Attaching a negative sign to the obtained result gives us -5.
Example 4. Add -5 and -10.
We represent -5 in 2’s complement form, i.e., 1111 1011. We represent -10 in 2’s complement form,
i.e., 1111 0110. Add the two numbers. The result is 1111 0001.
The result is in 2’s complement form.
To find the decimal equivalent of the result 1111 0001-
Find the 2’s complement of 1111 0001, i.e., 0000 1110 + 1 = 0000 1111. This is binary equivalent of +15. Attaching a negative sign to the obtained result gives us -15.
Subtraction of signed binary numbers – The subtraction of signed binary numbers is changed to the addition
of two signed numbers. For this, the sign of the second number is changed before performing the addition operation.
(-A) – (+B) = (-A) + (-B) (+B in subtraction is changed to –B in addition)
(+A) – (+B) = (+A) + (-B) (+B in subtraction is changed to –B in addition)
(-A) – (-B) = (-A) + (+B) (-B in subtraction is changed to +B in addition)
(+A) – (-B) = (+A) + (+B) (-B in subtraction is changed to +B in addition)
We see that the subtraction of signed binary numbers is performed using the addition operation.
The hardware logic for the fixed point number representation is simple, when we use 2’s complement
for addition and subtraction of the signed binary numbers.
4.2. Floating Point Number Representation
The floating point representation of a number has two parts
– mantissa and exponent. The mantissa is a signed fixed point number. The exponent shows the position of the binary point in the mantissa.
For example, the binary number +11001.11 with an 8-bit mantissa and 6-bit exponent is represented as follows -
- Mantissa is 01100111. The left most 0 indicates that the number is positive.
- Exponent is 000101. This is the binary equivalent of decimal number +5.
- The floating point number is Mantissa x 2^{exponent} i.e. + (.1100111) x 2^{+5}.
The arithmetic operation with the floating point numbers is complicated,
and uses complex hardware as compared to the fixed point representation.
However, floating point calculations are required in scientific calculations, so,
computers have a built-in hardware for performing floating point arithmetic operations.
5. Binary Coding Schemes
The alphabetic data, numeric data, alphanumeric data, symbols, sound data and video data, all are represented as
combination of bits in the computer. The bits are grouped in a fixed size, such as 8 bits, 6 bits or 4 bits.
A code is made by combining bits of definite size.
Binary Coding schemes represent the data such as alphabets, digits 0-9, and symbols in a standard code.
A combination of bits represents a unique symbol in the data.
The standard code enables any programmer to use the same combination of bits to represent a symbol in the data.
The binary coding schemes that are most commonly used are -
- Extended Binary Coded Decimal Interchange Code (EBCDIC),
- American Standard Code for Information Interchange (ASCII),and
- Unicode