Chap 9 - Number System & Bynary Arithmetic
Chap 9 - Number System & Bynary Arithmetic
Since the early days of human civilization, people have been using their fingers, sticks and other things
for counting. As daily activities became more complex, the numbers became more important in trade,
time and distance, and in all other spheres of human life. It became apparent that we needed more than
our fingers and toes to keep track of the number in our daily routine. In 3400 BC, the ancient Egyptians
started using special symbols for writing the numbers. This was a major advancement, because it
reduced the number of symbols required. However, it was difficult to represent large or small numbers
by using such a graphical approach.
Learning objectives
After studying this lesson, student should be able to:
I. DEFINITIONS.......................................................................................................................... 2
EXERCISES……………………………………………………………………………20
Topic: NUMBER SYSTEM & BINARY MATHEMATICS
I. DEFINITIONS
A number system defines a set of values that is used to represent quantity. The number systems can be
classified into two broad categories as follows:
-
Nonpositional Number Systems: In ancient times, people used to count on their fingers. When
the fingers became insufficient for counting, stones, pebbles or sticks were used to indicate the
values. This method of counting is called the nonpositional number system.
-
Positional Number Systems: In positional number systems, the value of each digit in a number is
defined not only by the symbol, but also by the symbol's position. Positional number systems are
characterized by the base or radix. The positional number system, which is currently used, is called the
decimal number system. This system is a base 10 system, that is, it contains 10 digits (0, 1, 2, 3 ...8, 9).
The base tells the number of symbols used in the system. Radix of the system is always expressed in
decimal numbers .Then the system of base n will use digits from 0 to n-1. E.g. the base or radix of the
decimal system is 10. This implies that there are 10 symbols: 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9. Base 3 uses the
digits 0, 1 and 2. Base 6 uses the digits 0, 1, 2, 3, 4 and 5.
The base of a number system is indicated by a subscript (decimal number) and this will be followed by
the value of the number. The following are few examples:
(7592)10 is of base 10 number system. - (214)8 is of base 8 number system. - (123)16 is of base 16 number system
We have discussed earlier that internally the computer uses binary numbers for data representation, whereas
externally it uses decimal numbers. However, any number in one number system can be represented in any
other number system. Conversion between number systems can be classified into three types: Coding,
decoding and encoding.
III.1. Coding
Coding is the conversion from decimal base (base 10) to any non-decimal base b (≠ 10).
Topic: NUMBER SYSTEM & BINARY MATHEMATICS
Examples: a) Determine the binary equivalent of (36)10. b) Convert (671)10 into base 6, then in Base 16
0.375 x 2 = 0.750 0
0.75 x 2 = 1.50 1
0.5 x 2 = 1.0 1
Finally, (0.375)10 = (0.011)2
We have already noticed in the previous question that (671)10 = (29F)16. Now let convert (0.175)10 in base 16
0.175 x 16 = 2.8 2
0.8 x 16 = 12.8 C
0.8 x 16 = 12.8 C
....
Finally, (671.175)10 = (29F.2CCC...)16
III. 2. Decoding
To decode is convert from a non-decimal base b ( ≠ 10) to the decimal base (base 10).
The conversion of fractions is similar to the decimal numbers. The only difference is the negative exponents,
which are used to denote the negative powers of b. Here, instead of a 'decimal' point we have a 'binary' point.
The exponential expressions of each fractional placeholder are b-1, b-2, and in this way the exponent notation
proceeds. The steps involved in the conversion process are as follows:
1. Write the weight value of each bit of the non decimal fractional number.
2. Multiply the weighted position with the respective bit of the non decimal fractional number.
3. Add all the weighted values to get the decimal number.
Sum of weight of all bits = 128 + 24 + 7 + 0 + 0.0625 = 159.0625 Thus, (237.04)8 = (159.0625)16
Determine the decimal equivalent of (45C.8BE3)16.
Sum of weight of all bits = 1024 + 80 + 12 +0.5 + .0429687 + .0034179 + .0000457= 1116.5464323
Topic: NUMBER SYSTEM & BINARY MATHEMATICS
III.3. Encoding
Encoding is the conversion from a non-decimal base to a non-decimal base. Some special cases would be
distinguished.
III.3.1 Conversion of Binary to Hexadecimal
The conversion of an integer binary number to hexadecimal is accomplished by the following steps:
1. Break the binary number into four-bit sections starting from the LSB to the MSB.
2. Convert the four-bit binary number to its hexadecimal equivalent.
For whole numbers, it may be necessary to add a zero to the MSB to complete a grouping of four bits.
NOTE: By adding a zero, the MSB will not change the value of the binary number.
Examples: a) Determine the hexadecimal equivalent of (101011110011011001)2
Converting a hexadecimal (base 16) number to a binary (base 2) number is a precise process. Since a
single digit in a hexadecimal number corresponds directly to a four-digit binary number, to convert
the hexadecimal number into its binary equivalent, the following steps are involved:
1. Convert each hexadecimal digit to its four-bit binary equivalent.
2. Combine the four-bit sections by removing the spaces to get the binary number.
Examples: Determine the binary equivalent of (5AF)16
Octal and hexadecimal have certain relations with binary, that is, the first digit in octal corresponds to the first
three digits in its binary equivalent and so on. The same is true for hexadecimal and this time each digit
represents four binary digits. This makes the conversion of octal to hexadecimal and vice versa quite easy. This
conversion involves the following steps:
1. Convert each octal digit to three-bit binary form.
2. Combine all the three-bit binary numbers.
3. Divide the binary numbers into the four-bit binary form by starting the first number
from the right bit to the first number from the left bit.
4. Finally, convert these four-bit blocks into their respective hexadecimal symbols
This conversion follows the same steps of octal to hexadecimal conversion except that each hexadecimal digit
is converted into a four-bit binary form and then after grouping of all the four bit binary blocks, it is converted
into the three-bit binary form. Finally, these three-bit binary forms are converted into octal symbols.
1 borrows 11 borrows
00100101 = (37)10 00110011 = (51)10
‐ 00010001 = (17)10 ‐ 00010110 = (22)10
00010100 = (20)10 00011101 = (29)10
x 1 2 3 4 5 6 7
1 1 2 3 4 5 6 7
2 2 4 6 10 12 14 16
3 3 6 11 14 17 22 25
4 4 10 14 20 24 30 34
5 5 12 17 24 31 36 43
6 6 14 22 30 36 44 52
Topic: NUMBER SYSTEM & BINARY MATHEMATICS
+ 1 2 3 4 5 6 7 8 9 A B C D E F 10
1 2 3 4 5 6 7 8 9 A B C D E F 10 11
2 3 4 5 6 7 8 9 A B C D E F 10 11 12
3 4 5 6 7 8 9 A B C D E F 10 11 12 13
4 5 6 7 8 9 A B C D E F 10 11 12 13 14
5 6 7 8 9 A B C D E F 10 11 12 13 14 15
6 7 8 9 A B C D E F 10 11 12 13 14 15 16
7 8 9 A B C D E F 10 11 12 13 14 15 16 17
8 9 A B C D E F 10 11 12 13 14 15 16 17 18
9 A B C D E F 10 11 12 13 14 15 16 17 18 19
A B C D E F 10 11 12 13 14 15 16 17 18 19 1A
B C D E F 10 11 12 13 14 15 16 17 18 19 1A 1B
C D E F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C
D E F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D
E F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E
F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
* 01 2 3 4 5 6 7 8 9 A B C D E F
0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 01 2 3 4 5 6 7 8 9 A B C D E F
2 02 4 6 8 A C E 10 12 14 16 18 1A 1C 1E
3 03 6 9 C F 12 15 18 1B 1E 21 24 27 2A 2D
4 04 8 C 10 14 18 1C 20 24 28 2C 30 34 38 3C
5 05 A F 14 19 1E 23 28 2D 32 37 3C 41 46 4B
6 0 6 C 12 18 1E 24 2A 30 36 3C 42 48 4E 54 5A
7 07 E 15 1C 23 2A 31 38 3F 46 4D 54 5B 62 69
8 0 8 10 18 20 28 30 38 40 48 50 58 60 68 70 78
9 0 9 12 1B 24 2D 36 3F 48 51 5A 63 6C 75 7E 87
A 0 A 14 1E 28 32 3C 46 50 5A 64 6E 78 82 8C 96
B 0 B 16 21 2C 37 42 4D 58 63 6E 79 84 8F 9A A5
C 0 C 18 24 30 3C 48 54 60 6C 78 84 90 9C A8 B4
D 0 D 1A 27 34 41 4E 5B 68 75 82 8F 9C A9 B6 C3
E 0 E 1C 2A 38 46 54 62 70 7E 8C 9A A8 B6 C4 D2
F 0 F 1E 2D 3C 4B 5A 69 78 87 96 A5 B4 C3 D2 E1
Topic: NUMBER SYSTEM & BINARY MATHEMATICS
The rules for signed and unsigned binary numbers are simple and are explained as follows:
• In an unsigned number, the MSB is a weighted position bit.
• In a signed number, the MSB (the sign bit) is 0 for a positive number.
• In a signed number, the MSB (the sign bit) is 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
7 7
sign bit is 1. An 8-bit signed number can represent data in the range -128 to +127 (-2 to +2 -1). In general,
n-1 n-1
using n bits, the range of integer we can store using two’s complement is -2 to 2
V.2 Complements
The complement of a number is the number, which when added to the original will make it equal to a
multiple of the base number system. The complement of a number can be used as a representation of that
number as a negative and as a positive number that represents a negative. It is a method, which can be used
to make the subtraction easier for machines. Consequently, complements are used in the digital computers
for simplifying the subtraction operation and for the logical operation.
For every base r system, there are two types of complements: rs complement and (r – 1)s complement.
• For decimal r = 10, we have 9s and 10s complement.
• For binary r = 2, we have 1s and 2s complement.
• For octal r = 8, we have 7s and 8s complement.
• For hexadecimal r = 16, we have 15s and 16s complement.
There are two types of complements for the binary number system: 1’scomplement and
2’scomplement.
Topic: NUMBER SYSTEM & BINARY MATHEMATICS
To form the negative of any number, first complement all the bits of that number. This result is known as the 1s
complement of the original number. This requires changing every logic 1 bit in a number to logic 0, and every
logic 0 bit to logic 1. For instance :
• 1’s complement of 110 is 001
• 1’s complement of 1011 is 0100
• 1’s complement of 1101111 is 0010000
The 2’s complement is the convention used in most of the computers to represent negative numbers. To obtain
the 2s complement of a number, there is a two-step process:
1. 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.
2. 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.
Taking the 2s complement of the number will cause the MSB to become 1. Using n bits, the range of integer we
n-1 n-1
can store using two’s complement is -2 to 2 -1
For instance : - 2’s complement of 110 is 001 + 1 = 010
• 2’s complement of 1011 is 0100 + 1 = 0101
• 2’s complement of 1101111 is 0010000 + 1 = 0010001
• 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.
The table below shows the representation of the signed number 18.
+18 Sign bit is 0.
00010010
0010010 is binary equivalent of +18
Sign bit is 1.
Signed magnitude representation 10010010
0010010 is binary equivalent of +18
Sign bit is 1.
-18 Signed 1’s complement representation 11101101
1101101 is 1‘s complement of +18
Sign bit is 1.
Signed 2’s complement representation 11101110
1101110 is 2‘s complement of +18
Signed magnitude and signed 1‘s complement representation are seldom used in computer arithmetic.
Representation Comparison for 8-bit Binary Numbers
We are familiar with the fact that any number can be written as a fraction multiplied by 10 to some power. For
3 -1
instance: 123 can be written as 0.123 x 10 - 0.0187 can be written as 0.187 x 10
2
-57.3 can be written as -0.573 x 10
- The sign bit is 0 for a positive number and 1 for a negative number
- The mantissa is to be treated as a binary fraction, where the binary point is assumed to be placed
immediately in front of the leftmost bit. Thus the mantissa 1001 is taken to mean the binary fraction
0.1001
- The exponent is stored using ‗sign and magnitude‘. With 3 bits the range of exponent is -3 to +3. -3
is stored as 111 and +3 is stored as 011
Examples: 1) What floating number is represented by 001011010
- The sign is positive - The mantissa is 1010 represented the number 0.1010 - The exponent is 010 which
represent 2
2
Therefore the number represented is 0.1010 x2 = (10.10)2 = (2.5)10
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 (27)10 and (−11)10 using complementary representation for the negative value.
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.
Here we do subtraction using addition! We use the signed 1’s or 2’s complement representation to represent
the negative numbers. The subtraction here is just supposed to be an addition of a positive number and a
negative number. Then:
• (-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)
Topic: NUMBER SYSTEM & BINARY MATHEMATICS
Examples
With 2’s complement With 1’s complement
1. Add −8 to +3 3. Add −8 to +3
(+3) 0000 0011 (+3) 0000 0011
+(−8) 1111 1000 +(−8) 1111 0111
----------------- --------------------------
(−5) 1111 1011 (−5) 1111 1010
2. Add −5 to −2 4. Add −5 to −2
(−2) 1111 1110 (−2) 1111 1101
+(−5) 1111 1011 +(−5) 1111 1010
----------------- --------------------------
(−7) 1 1111 1001 : discard carry-out 1 1111 0111
+(1) 1: Add carry-out
----------------------------
(−7) 1111 1000
If the result of an arithmetic operation is to too large (positive or negative) to fit into the resultant bit-group, then
arithmetic overflow occurs. In general, overflow occurs when adding two positive numbers produces a negative
result, or when adding two negative numbers produces a positive result. Adding operands of unlike signs never
produces an overflow. Notice that discarding the carry out of the most significant bit during Two's Complement
addition is a normal occurrence, and does not by itself indicate overflow
As an example of overflow, consider adding (80 + 80 = 160)10, which produces a result of − 9610 in 8-bit two's
complement:
01010000 = 80
+ 01010000 = 80
--------------
10100000 = −96 (not 160 because the sign bit is 1.) (largest +ve number in 8 bits is 127)
Topic: NUMBER SYSTEM & BINARY MATHEMATICS
Binary code decimal digits (0–9) are represented by using four bits. The valid combinations of y and
their respective values are shown in the table below.
To represent the signs + and -, any of the remaining 4 bits patterns can be used. One convention uses 1010 for
+ and 1011 for -. You can see that in one byte we can have either 2 digits or a sign and one digit. Here we must
use the full 4-bits representation of any digit (including the leading 0s). Thus the BCD representation of 5319 is
0101001100011001 and not 101001100011001
EBCDIC is an acronym for Extended Binary Coded Decimal Interchange Code, Invented by IBM. It is a
single byte (8 bit) character encoding standard that is used in the IBM mainframe environment. IBM didn't
invent just one version of EBCDIC either but several different incompatible versions. The computing
friendly and user friendly thing would have been to use the already in existence ASCII standard.
• The Extended Binary Coded Decimal Interchange Code(EBCDIC) uses 8 bits (4 bits for zone,
4 bits for digit) to represent a symbol in the data.
8
• EBCDIC allows 2 = 256 combinations of bits.
• 256 unique symbols are represented using EBCDIC code. It represents decimal numbers (0-9),
lower case letters (a-z), uppercase letters (A-Z), Special characters, and Control characters
(printable and non-printable e.g. for cursor movement, printer vertical spacing etc.).
• EBCDIC codes are used, mainly, in the mainframe computers.
VI.4 Unicode
Unicode is a universal character encoding standard for the representation of text which includes letters,
32
numbers and symbols in multi-lingual environments. It uses 32 bits (2 = 4164895296 combinations) to
represent a symbol in the data. Unicode codes can uniquely represent any character or symbol present in any
language like Chinese, Japanese, included mathematical and scientific symbols are also represented in
Unicode codes. An advantage of Unicode is that it is compatible with the ASCII-8 codes. The first 256 codes
in Unicode are identical to the ASCII-8 codes.
Topic: NUMBER SYSTEM & BINARY MATHEMATICS
EXERCISES
MCQ
1. Choose the correct answer from below for the result of the binary multiplication 1101 × 110.
(a) 1001111, (b) 1010110, (c) 1001110, (d) 1011111.
2. Choose the correct answer from below for the result of the binary division 11011 ÷ 1001.
(a) 10, (b) 101, (c) 11, (d) 110.
Exercise 1.
(a) Convert the binary number 1011 into decimal form.
(b) Convert the binary number 1.011 into decimal form.
(c) Convert the numbers 15 and 12 into binary form, add the two binary numbers together and
convert the answer to decimal form to check that the sum is correct.
(d) Convert the numbers 9 and 6 into binary form. Use this to find 9 − 6 in binary form. Check
that the answer is correct by converting the binary answer into decimal form.
Exercise 2.
In each of the questions below, a product is written in decimal form. In each case, convert both numbers to
binary form, multiply them in binary form and check that the solution is correct by converting the answer to
decimal form. (Click on the green letters for solutions.)
(a) 3 × 2, (b) 4 × 4, (c) 5 × 10, (d) 6 × 7, (e) 9 × 6, (f) 11 × 7
Exercise 3.
In each of the questions below, a division is written in decimal form. In each case, convert both numbers to
binary form, perform the division in binary form and check that the solution is correct by converting the answer
to decimal form. (Click on the green letters for solutions.)
(a) 6 ÷ 2, (b) 8 ÷ 2, (c) 9 ÷ 3, (d) 10 ÷ 4, (e) 21 ÷ 7, (f) 18 ÷ 8.
Topic: NUMBER SYSTEM & BINARY MATHEMATICS
1) What is the smallest and the largest floating point value which may be represented using the representation described in
the note?
2) What floating point numbers are represented by
a) 1 001 1100 b) 1 100 0101 (c) 0 101 1100 d) 1 111 1111 e) 0 000 1000 f) 0 010 1110
3) Using the representation described in the note, give the floating point representation of each of the following.
State whether the representation is exact or not. If inexact calculate the error in the representation.
(a) 5.25 (b) 2.1875 (c) -4.5 (d) 7.35 (e) -3.3 (f) 6.256 (g) -7.7 (h) 1.115 (i) -3.75
4) Numbers are stored in an 8-bits byte of a computer in a normalized floating point representation as follow:
S M E
5) A certain computer uses 11-bits words for storing a floating point number:
- 1 bit represent the sign, S; 0 for positive and 1 for negative
- The exponent, E, is a 4-bits value, stored in 2‘s complement form
- The mantissa, M, is a 6-bits normalized value, with the binary point assumed to be just in front of the leftmost bit
Give the representation of : 0.3, 7.3 and 6.375, Stating the error in each representation.
(a) What is the lowest possible value for an 8-bit signed magnitude binary number?
(b) What is the highest possible value for a 10-bit 2's complement binary number?
4. Convert each of the following 8-bit signed magnitude binary numbers to decimal.
a) 100111012 b) 000101012 c) 111001102 d) 011010012
5.. Using 1’s and 2’s complements perform the following subtractions
a. 100110 – 11011 c. 1101010 – 110100 b. 10011.1101 – 101.11 d. 1010 – 11011
6.
(a) What is the lowest possible value for an 8-bit signed magnitude binary number?
(b) What is the highest possible value for a 10-bit 2's complement binary number?
Exercise 7
Find the following differences using 2’s complement arithmetic. First convert decimal values to corresponding
binary values. Next, find the two’s complement representation of the subtrahend. Add the minuend and 2’s
complemented subtrahend. Check your answers.
a) 12 – 6 b) 4 – 6 c) 3.125 – 6.5 d) 67.25 – 83.125
Topic: NUMBER SYSTEM & BINARY MATHEMATICS