We use computer to process the data and get the desired output. The data input can be in the form of alphabets, digits, symbols, audio, video, magnetic cards, finger prints, etc. Since computer can only understand 0 and 1, the data must be represented in the computer in 0s and 1s. The purpose of this chapter is to introduce you to the data representation in the computer.
The data stored in the computer may be of different kinds, as follows—
All kinds of data, be it alphabets, numbers, symbols, sound data or video data, is represented in terms of 0s and 1s, in the computer. Each symbol is represented as a unique combination of 0s and 1s.
This chapter discusses the number systems that are commonly used in the computer. The number systems discussed in this chapter are—(1) Decimal number system, (2) Binary number system, (3) Octal number system, and (4) Hexadecimal number system. The number conversions described in this chapter are—
The chapter also discusses the binary arithmetic operations and the representation of signed and unsigned numbers in the computer. The representation of numbers using binary coding schemes and the logic gates used for the manipulation of data are also discussed.
A number system in base r or radix r uses unique symbols for r digits. One or more digits are combined to get a number. The base of the number decides the valid digits that are used to make a number. In a number, the position of digit starts from the right-hand side of the number. The rightmost digit has position 0, the next digit on its left has position 1, and so on. The digits of a number have two kinds of values—
The face value of a digit is the digit located at that position. For example, in decimal number 52, face value at position 0 is 2 and face value at position 1 is 5.
The position value of a digit is (baseposition). For example, in decimal number 52, the position value of digit 2 is 100 and the position value of digit 5 is 101. Decimal numbers have a base of 10.
The number is calculated as the sum of, face value * baseposition, of each of the digits. For decimal number 52, the number is 5*101 + 2*100 = 50 + 2 = 52
In computers, we are concerned with four kinds of number systems, as follows—
The numbers given as input to computer and the numbers given as output from the computer, are generally in decimal number system, and are most easily understood by humans. However, computer understands the binary number system, i.e., numbers in terms of 0s and 1s. The binary data is also represented, internally, as octal numbers and hexadecimal numbers due to their ease of use.
A number in a particular base is written as (number)base of number For example, (23)10 means that the number 23 is a decimal number, and (345)8 shows that 345 is an octal number.
Table 5.1 summarizes the base, digits and largest digit for the above discussed number systems. Table 5.2 shows the binary, octal and hexadecimal equivalents of the decimal numbers 0–16.
Table 5.1 Summary of number system
Table 5.2 Decimal, binary, octal and hexadecimal equivalents
A decimal number has two parts—integer part and fraction part. For example, in the decimal number 23.0786, 23 is the integer part and .0786 is the fraction part. The method used for the conversion of the integer part of a decimal number is different from the one used for the fraction part. In the following subsections, we shall discuss the conversion of decimal integer, decimal fraction and decimal integer.fraction number into binary, octal and hexadecimal number.
A decimal integer is converted to any other base, by using the division operation.
To convert a decimal integer to—
Let us now understand this conversion with the help of some examples.
Example 1: Convert 25 from Base 10 to Base 2.
to Base | Number (Quotient) |
Remainder |
---|---|---|
2 |
25 |
|
to Base | Number (Quotient) |
Remainder |
---|---|---|
2 |
25 |
|
2 |
12 |
1 |
2 |
6 |
0 |
2 |
3 |
0 |
2 |
1 |
1 |
0 |
1 |
The binary equivalent of number (25)10 is (11001)2
The steps shown above are followed to convert a decimal integer to a number in any other base.
Example 2: Convert 23 from Base 10 to Base 2, 8, 16.
Example 3: Convert 147 from Base 10 to Base 2, 8 and 16.
Example 4: Convert 94 from Base 10 to Base 2, 8 and 16.
A fractional number is a number less than 1. It may be .5, .00453, .564, etc. We use the multiplication operation to convert decimal fraction to any other base.
To convert a decimal fraction to—
Steps for conversion of a decimal fraction to any other base are—
Example 5: Convert 0.2345 from Base 10 to Base 2.
The binary equivalent of (0.2345)10 is (0.001111)2
Example 5a: Convert 0.865 from Base 10 to Base 2,8 and 16.
A decimal integer.fraction number has both integer part and fraction part. The steps for conversion of a decimal integer.fraction to any other base are—
Example 6: Convert 34.4674 from Base 10 to Base 2.
Example 7: Convert 34.4674 from Base 10 to Base 8.
Example 8: Convert 34.4674 from Base 10 to Base 16.
A binary, octal or hexadecimal number has two parts—integer part and fraction part. For example, a binary number could be 10011, 0.011001 or 10011.0111. The numbers 45, .362 or 245.362 are octal numbers. A hexadecimal number could be A2, .4C2 or A1.34.
The method used for the conversion of integer part and fraction part of binary, octal or hexadecimal number to decimal number is the same; multiplication operation is used for the conversion. The conversion mechanism uses the face value and position value of digits. The steps for conversion are as follows—
Example 9: Convert 1011 from Base 2 to Base 10.
Convert 62 from Base 8 to Base 10.
Convert C15 from Base 16 to Base 10.
Example 10: Convert .1101 from Base 2 to Base 10.
Convert .345 from Base 8 to Base 10.
Convert .15 from Base 16 to Base 10.
Example 11: Convert 1011.1001 from Base 2 to Base 10.
Convert 24.36 from Base 8 to Base 10.
Convert 4D.21 from Base 16 to Base 10.
A binary number can be converted into octal or hexadecimal number using a shortcut method. The shortcut method is based on the following information—
The Steps for Binary to Octal Conversion are—
The Steps for Binary to Hexadecimal Conversion are—
Example 12: Convert the binary number 1110101100110 to octal.
Given binary number |
1110101100110 |
Example 13: Convert the binary number 1110101100110 to hexadecimal
Given binary number |
1110101100110 |
The conversion of a number from octal and hexadecimal to binary uses the inverse of the steps defined for the conversion of binary to octal and hexadecimal.
The Steps for Octal to Binary Conversion are—
The Steps for Hexadecimal to Binary Conversion are—
Example 14: Convert the hexadecimal number 2BA3 to binary.
Example 15: Convert the octal number 473 to binary.
The arithmetic operations—addition, subtraction, multiplication and division, performed on the binary numbers is called binary arithmetic. In computer, the basic arithmetic operations performed on the binary numbers is—
In the following subsections, we discuss the binary addition and the binary subtraction operations.
Binary addition involves addition of two or more binary numbers. The binary addition rules are used while performing the binary addition. Table 5.3 shows the binary addition rules.
Table 5.3 Binary addition rules
Binary addition of three inputs follows the rule shown in Table 5.4.
Table 5.4 Binary addition of three inputs
Addition of the binary numbers involves the following steps—
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.
Example 4: Add 1101 and 1111. Verify the answer with the help of decimal addition.
Example 5: Add 10111, 11100 and 11. Verify theanswer with the help of decimal addition.
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 5.5, where “Input 2” is subtracted from “Input 1.”
Table 5.5 Binary subtraction rules
The steps for performing subtraction of the binary numbers are as follows—
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 100110 from 110001. Verify the answer with the help of decimal subtraction.
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 (–27to +27−1). The left-most 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 (28 = 256).
Complements are used in computer for the simplification of the subtraction operation. For any number in base r, there exist two complements—(1) r’s complement and (2) r-1 ’s complement.
Number System | Base | Complements possible |
---|---|---|
Binary |
2 |
1’s complement and 2’s complement |
Octal |
8 |
7’s complement and 8’s complement |
Decimal |
10 |
9’s complement and 10’s complement |
Hexadecimal |
16 |
15’s complement and 16’s complement |
Let us now see how to find the complement of a binary number. There are two types of complements for the binary number system—1’s complement and 2’s complement.
1’s complement of 101 is 010
1’s complement of 1011 is 0100
1’s complement of 1101100 is 0010011
2’s complement of 101 is 010 + 1 = 011
2’s complement of 1011 is 0100 + 1 = 0101
2’s complement of 1101100 is 0010011 + 1 = 0010100
The rule to find the complement of any number N in base r having n digits is
(r − 1)’s complement—(rn − 1) − N
(r’s) complement2—(rn − 1) − N + 1 = (rn − N)
A binary number may also have a binary point, in addition to the sign. The binary point is used for representing fractions, integers and integer-fraction numbers. Registers are high-speed storage areas within the Central Processing Unit (CPU) of the computer. All data are brought into a register before it can be processed. For example, if two numbers are to be added, both the numbers are brought in registers, added, and the result is also placed in a register. There are two ways of representing the position of the binary point in the register—fixed point number representation and floating point number representation.
The fixed point number representation assumes that the binary point is fixed at one position either at the extreme left to make the number a fraction, or at the extreme right to make the number an integer. In both cases, the binary point is not stored in the register, but the number is treated as a fraction or integer. For example, if the binary point is assumed to be at extreme left, the number 1100 is actually treated as 0.1100.
The floatingpoint number representation uses two registers. The first register stores the number without the binary point. The second register stores a number that indicates the position of the binary point in the first register.
We shall now discuss representation of data in the fixed point number representation and floating point number representation.
The integer binary signed number is represented as follows—
Table 5.6 shows the representation of the signed number 18.
Table 5.6 Fixed point representation of the signed number 18
Signed magnitude and signed 1’s complement representation are seldom used in computer arithmetic.
Let us now perform arithmetic operations on the signed binary numbers. We use the signed ’s complement representation to represent the negative numbers.
Please note that the negative output is automatically in the ’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 us understand the addition of two signed binary numbers with the help of some examples.
Example 1: Add +5 and +10.
+5 in binary form, i.e., 0000 0101. +10 in binary form, i.e., 0000 1010.
Example 2: Add −5 and +10.
−5 in ’s complement form is 1111 1011. +10 in binary form is 0000 1010.
Example 3: Add +5 and −10.
+5 in binary form is 0000 0101. −10 in ’s complement form is 1111 0110. 1111 1011.
The result is in 2’s complement form. To find its decimal equivalent—
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.
−5 in ’s complement form is 1111 1011. −10 in 2’s complement form is 1111 0110.
The result is in 2’s complement form. To find its decimal equivalent—
Find the ’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.
(−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 ’s complement for addition and subtraction of the signed binary numbers. When two large numbers having the same sign are added, then an overflow may occur, which has to be handled.
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—
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.
The alphabetic data, numeric data, alphanumeric data, symbols, sound data and video data, 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—
In the following subsections, we discuss the EBCDIC, ASCII and Unicode coding schemes.
If you wish to see the Unicode character encoding in MS−Word 2007, do as follows—
<Insert> <Symbol>. A Symbol dialog box will appear which displays the symbols, and the character codes in a coding scheme, as shown in Figure 5.1.
Figure 5.1 Unicode coding
The information is represented in the computer in binary form. Binary information is represented using signals in two states off or on which correspond to 0 or 1, respectively. The manipulation of the binary information is done using logic gates. Logic gates are the hardware electronic circuits which operate on the input signals to produce the output signals. Each logic gate has a unique symbol and its operation is described using algebraic expression. For each gate, the truth table shows the output that will be outputted for the different possible combinations of the input signal. The AND, OR and NOT are the basic logic gates. Some of the basic combination of gates that are widely used are—NAND, NOR, XOR and XNOR.
Table 5.7 shows the different logic gates, their symbols, their algebraic function and the truth table for each logic gate. The comments list the features of each logic gate.
Table 5.7 Logic gates
1’s Complement |
ASCII-7 |
Binary Subtraction |
2’s Complement |
ASCII-8 |
Conversions |
Alphabetic Data |
Base or Radix |
Decimal Number |
Alphanumeric Data |
Binary Addition |
Digit Bits |
American Standard Code for |
Binary Arithmetic |
Exponent |
Information Interchange |
Binary Coding Schemes |
Extended Binary Coded |
(ASCII) |
Binary Number |
Decimal Interchange Code |
AND Gate |
Binary Point |
(EBCDIC) |
Face Value |
Number |
Signed Magnitude |
Fixed Point Number |
Number System |
Representation |
Representation |
Numeric Data |
Signed Number |
Floating Point Number |
Octal Number |
Truth Table |
Representation |
OR Gate |
Unicode |
Fraction |
Position |
Unicode Transformation |
Hexadecimal Number |
Position Value |
Format (UTF) |
Integer |
r−1’s Complement |
Unsigned Number |
Logic Gates |
r’s Complement |
UTF-8 |
Mantissa |
Signed 1’s Complement |
XNOR Gate |
Most Significant Bit (MSB) |
Representation |
XOR Gate |
NAND Gate |
Signed 2’s Complement |
Zone Bits |
NOR Gate |
Representation |
|
NOT Gate |
|
|
Section 5.2–5.3.3
1. What is the significance of the base of the number?
2. Explain the significance of the face value and position value of a number. Give an example.
3. What is the position value of a digit?
4. The decimal number system is in base _____.
5. The binary number system is in base _____.
6. The octal number system is in base _____.
7. The hexadecimal number system is in base _____.
8. Give the valid digits in the number systems—(a) decimal, (b) binary, (c) octal, and (d) hexadecimal.
9. Write the largest digit in the number systems—(a) decimal, (b) binary, (c) octal, and (d) hexadecimal.
10. How many valid digits are there in the number systems—(a) decimal, (b) binary, (c) octal, and (d) hexadecimal?
11. Show the octal, binary and hexadecimal equivalent of the decimal number 11.
12. Convert the following decimal numbers into binary, octal and hexadecimal.
Section 5.4
13. Convert the following binary numbers into decimal numbers.
14. Convert the following octal numbers into decimal numbers.
15. Convert the following hexadecimal numbers into decimal numbers.
Section 5.5
16. Convert the following binary into octal.
17. Convert the following binary into hexadecimal.
Section 5.6
18. Convert the following octal into binary
19. Convert the following hexadecimal into binary.
Section 5.7
20. Perform binary addition on the following binary numbers.
21. Perform binary subtraction on the following binary numbers.
Section 5.7.1
22. Find 1’s complement of the following binary numbers.
23. Find ’s complement of the following binary numbers.
24. What is the relation between the 1’s complement and ’s complement of a binary number?
Section 5.8–5.8.2
25. In addition to the digits, a number may contain a _____ and _____.
26. What is a sign bit?
27. Which bit is considered as a sign bit when representing a number?
28. What is the value of sign bit for a positive number?
29. What is the value of sign bit for a negative number?
30. What is the range of data that can be represented using an 8−bit signed number?
31. What is the range of data that can be represented using an 8−bit unsigned number?
32. _____ representation and _____ representation are the two ways of representing the position of the binary point in the register.
33. Represent the following as 8−bit numbers in (a) Signed Magnitude representation, (b) Signed 1’s complement representation, and (c) Signed ’s complement representation
34. Represent the following as 8-bit numbers in Fixed Point number representation.
35. Perform binary addition of the following numbers.
36. Perform binary subtraction of the following numbers
37. Represent the following binary numbers in Floating Point number representation.
Section 5.9
38. Why are binary coding schemes needed?
39. List any four commonly used binary coding schemes.
40. What number of bits is used to represent the following codes—(a) EBCDIC, (b) ASCII-7, and (c) ASCII−8?
41. How many characters can be represented in the following codes—(a) EBCDIC, (b) ASCII-7, and (c) ASCII-8?
42. How is Unicode different from the other Binary coding schemes? (Hint: multilingual, no. of characters)
43. What is UTF-8 character encoding?
Section 5.10
44. Name the basic logic gates.
45. Draw the symbols of the following logic gates—(a) AND, (b) OR, (c) NOT, (d) NAND, (e) NOR, (f) XOR, and (g) XNOR.
46. Write the truth table of the following logic gates—(a) AND, (b) OR, (c) NOT, (d) NAND, (e) NOR, (f) XOR, and (g) XNOR.
47. Write the algebraic function of the following logic gates− (a) AND, (b) OR, (c) NOT, (d) NAND, (e) NOR, (f) XOR, and (g) XNOR.
Extra Questions
48. Give full form of the following abbreviations
49. Write short notes on
50. Give differences between the following
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23
33(a)
33(b)
33(c)
34.
35.
36.
37.
18.188.190.175