<<

DATA REPRESENTATION : SYSTEMS

Introduction to Number Systems In order to represent the characters on the keyboard(letter, , special symbols, function keys etc) a coding systm is used. Each character is mapped onto the sysytem ucing ASCII or . So for example the letter ‘A’ on the keyboard is represented as 65 in and then this is converted to equivalent to be stored on the . So we need to study the various number systems used to represent in a computer. A number system is a method to represent (write) numbers. Every number system has a set of unique numbers or constants. The total count of the unique numbers is the base of the number system. There are basically four number systems which we need to study.

Number Systems

Decimal Binary

Decimal Number System: Decimal Number system composed of 10 numerals or symbols. These numerals are 0 to 9. Using these symbols as digits we can express any quantity. It is also called base-10 system. It is a positional value system in which the value of a digit depends on its position. These digits can represent any value, for example: consider the number: 754.

The value is formed by the sum of each digit, multiplied by the base (in this case it is 10 because there are 10 digits in decimal system) in power of digit position ( from zero):

Binary Number System: In Binary Number system there are only two digits i.e. 0 or 1. It is base-2 system. It can be used to represent any quantity that can be represented in decimal or other number system. It is a positional value system, where each binary digit has its own value or weight expressed as power of 2.

The following are some examples of binary numbers:

1011012

112

101102

Octal Number System: It has eight unique symbols i.e. 0 to 7. It has base of 8. Each octal digit has its own value or weight expressed as a power of 8.

Hexadecimal Number System: The hexadecimal system uses base 16. It has 16 possible digit symbols. It uses the digits 0 through 9 plus the letters A,B,,,E,F as 16 digit symbols. Each hexadecimal digit has its own value or weight expressed as a power of 16.

To convert between the various number systems we need to create a simple table of values with nos representing equivalent digits in various number systems.

Table to remember

Decimal Binary Hexadecimal Octal 0 0 0 0 1 1 1 1 2 10 2 2 3 11 3 3 4 100 4 4 5 101 5 5 6 110 6 6 7 111 7 7 8 1000 8 10 9 1001 9 11 10 1010 A 12 11 1011 B 13 12 1100 C 14 13 1101 D 15 14 1110 E 16 15 1111 F 17

Number Conversions

We shall now study how conversions between the various number systems take place.

Conversion from Decimal to other Number Systems We can represent a decimal number in any other number system (binary, octal or hexadecimal), by simply converting it to the required format. The following steps can be followed for the same:

Step 1: Divide the decimal number by the base value of the number system in which it is to be converted (i.e.. 2 for binary, for octal and 16 for hexadecimal) Step 2: Store the remainder of at each step Step 3: Keep on dividing the by the base value till the quotient is zero Step 4: Now write the remainders(numbers) in the reverse order (from bottom to top) to form the equivalent number in the required base.

Decimal to Binary conversion Since the binary number system is of base 2 so we keep on dividing the given decimal number by 2 till the quotient becomes 0. Example : To convert 45 to equivalent binary number (45)10 = (?)2 Qoutient Qoutient/2 Remainder 45 45/2 1 Read the numbers from bottom to 22 22/2 0 top i.e. from Most Significant 11 11/2 1 (MSB) to Least Significant Bit 5 5/2 1 (LSB) 2 2/2 0

1 1/2 1 0

So the answer is : 101101 We can say that (45)10 = (101101)2

Decimal to Octal conversion Since the Octal number system is of base 8 so we keep on dividing the given decimal number by 8 till the quotient becomes 0. Example : To convert 65 to equivalent octal number (65)10 = (?)8 Qoutient Qoutient/8 Remainder 65 65/8 1 Read the numbers from bottom to 8 8/8 0 top i.e. from Most Significant 1 1/8 1 Bit(MSB) to Least Significant Bit 0 (LSB)

So the answer is : 101 We can say that (65)10 = (101)8

The following table shows the equivalent octal number for decimal numbers from 1 to 15 Decimal Octal 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 10 9 11 10 12 11 13 12 14 13 15 14 16 15 17

Decimal to Hexadecimal conversion Since the Hexadecimal number system is of base 16 so we keep on dividing the given decimal number by 16 till the quotient becomes 0. However in the hexadecimal number system , the numbers from 10 to 15 are represented by albhabets A through F. Consider the following table: Decimal Hexadecimal 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 A 11 B 12 C 13 D 14 E 15 F

Example : To convert 65 to equivalent hexadecimal number (65)10 = (?)16 Qoutient Qoutient/16 Remainder Read the numbers from bottom to 65 65/16 1 top i.e. from Most Significant 4 4/16 4 Bit(MSB) to Least Significant Bit 0 (LSB)

So the answer is : 41 We can say that (65)10 = (41)16

Lets do another example: (45)10 = (?)16 Qoutient Qoutient/16 Remainder 45 45/16 13 The equivalent of 13 is D in base 2 2/16 2 16, so the number is 2D 0

Answer : 2D

Converting decimal to other number systems For this we need to follow the following steps: Step 1: Multiply the fractional part by the base value of the reqired equivalent number system. Step 2: store the integer part of the product achieved Step 3: Keep on repeating the above till the fractional part becomes 0 or upto a given number of decimal places, if it is a recurring e.g, 0.33 Step 4: Read the number from top to bottom.

Converting decimal fraction to binary We multiply the fractional part with 2 untill th fractional part becomes 0.

Example: Let’s convert 0.625 to binary (0.625)10 = (?)2

Fractional part x 2 Product Integer part 0.625*2 1.250 1 0.250*2 0.500 0 0.500*2 1.000 1

Therefore (0.625)10 = (0.101)2

Converting decimal fraction to Octal We multiply the fractional part with 8 until the fractional part becomes 0.

Example: Let’s convert 0.425 to octal (0.425)10 = (?)8

Fractional part x 8 Product Integer part 0.425*8 3.4 3 0.4*8 3.2 3 This calculation will not give o 0.2*8 1.6 1 in the fractional part so we stop 0.6*8 4.8 4 after having upto 4 digits(depends on question Therefore (0.425)10 = (0.3314)8 also) Uptill 4 decimal places.

Converting decimal fraction to Hexadecimal We multiply the fractional part with 16 until the fractional part becomes 0.

Example: Let’s convert 0.425 to Hexadecimal (0.425)10 = (?)16

Fractional part x 16 Product Integer part 0.42516 6.8 6 0.8*16 12.8 12=C This calculation will not give 0 0.8*16 12.8 12=C in the fractional part so we stop 0.8*16 12.8 12=C after having upto required number of didgits Therefore (0.425)10 = (0.6CCC)8 Uptil 4 decimal places.

Converting from other number systems to decimal This requires obtaining the positional values of digits in a number. Step 1: Write down the digits of the given number Step 2: Multiply each digit with its positional value(d x base positional unit) Step 3: Add up the values . Step 4: The sum is the decimal equivalent of the given number

Binary to Decimal Conversion

Let us convert the binary number 110011 to its equivalent decimal number.

Binary Digit 1 1 0 0 1 1 Base positional unit 25 24 23 22 21 20 d x bp 1x25 1 x 24 0 x 23 0 x 22 1 x 21 1 x 20 Positional 32 16 0 0 2 1 Value

To obtain the decimal number, we add up the values: 32+16+0+0+2+1=51 Therefore : (110011)2 = (51)10

For fractional binary numbers we can extend the same to the right of the decimal number with base raised to -1, -2 etc. Example : Let us convert 1100.11 to equivalent decimal number:

Binary Digit 1 1 0 0 . 1 1 Base positional 23 22 21 20 . 2-1 2-2 unit d x bp 1x23 1 x 22 0 x 21 0 x 20 . 1 x 2-1 1 x 2-2 Positional 8 4 0 0 0.5 0.25 Value

Thus the equivalent decimal number will be : 8+4+0+0+0.5+0.25=12.75

Octal to Decimal Conversion

Let us convert the octal number 56.24 to its equivalent decimal number

Octal Digit 5 6 . 2 4 Base positional unit 81 80 8-1 8-2 d x bp 5x81 6 x 80 2 x 8-1 4 x 8-2 Positional Value 40 6 0.25 0.0625

To obtain the decimal number, we add up the values: 40+6+0.25+0.0625=46.3125 Therefore : (56.24)8 = (46.3125)10

Hexadecimal to Decimal Conversion

Let us convert the hexadecimal number 2D.74 to its equivalent decimal number.

Hexadecimal 2 D=13 . 7 4 Digit Base positional unit 161 160 16-1 16-2 d x bp 2x161 13 x 7 x 16- 4 x 16-2 160 1 Positional Value 32 13 0.4375 0.015625

To obtain the decimal number, we add up the values: 32+13+0.4375+0.015625 = 45.453125 Therefore : (2D.74)16 = (45.453125)10

Binary to octal conversion To convert a binary umber to octal, we group the digits with 3 digits in each group to represent an octal digit(23 = 8). We group from right to left before the decimal point and left to right after the decimal point. Example : Let us convert 11110011 to octal. Now we can see that the digits can be grouped into 3 each, but since there are 8 digits the left most group has 2 digits. So we add a 0 to the leftmost . In this case 3 groups are formed.

0 1 1 1 1 0 0 1 1

After grouping , we find the octal equivalent of the binary number using this table:

Binary Octal 000 0 001 1 010 2 011 3 100 4 101 5 110 6 111 7

0 1 1 1 1 0 0 1 1

3 6 3

Therefore the equivalent octal number is 363. Example: Convert 111110.11 to octal.

The groups would be:

1 1 1 1 1 0 . 1 1 0

7 6 . 6 Octal Equivalent

Binary to Hexadecimal conversion To convert a binary umber to octal, we group the digits with 4 digits in each group to represent an Hexadecimal digit(24 = 16). We group from right to left before the decimal point and left to right after the decimal point. Example : Let us convert 11101011110011 to hexadecimal. Now we can see that the digits can be grouped into 4 each, but the leftmost group has 2 digits. So we add two 0 to the leftmost group . In this case 4 groups are formed.

0 0 1 1 1 0 1 0 1 1 1 1 0 0 1 1

After grouping , we find the hexadecimal equivalent of the binary number using this table: Binary Hexadecimal 0000 0 0001 1 0010 2 0011 3 0100 4 0101 5 0110 6 0111 7 1000 8 1001 9 1010 A 1011 B 1100 C 1101 D 1110 E 1111 F

0 0 1 1 1 0 1 0 1 1 1 1 0 0 1 1

3 A F 3

Therefore the equivalent hexadecimal number is 3AF3. Thus (11101011110011)2 = (3AF3)16

Example: Convert 1110110.111 to hexadecimal.

The groups would be

1 1 1 1 0 1 1 0 . 1 1 1 0

Hexadecim F 6 . E al Number

Converting Octal and Hexadecimal numbers to binary We can conert from octal or hexadecimal number to binary by finding the binary equivalent of each digit in the given number and joining these to form a .

Example: To convert the octal number 647 to binary. Using the table given above, we can find the binary equivalent of the digits 6, 4 and 7

Octal digits 6 4 7 Binary equivalent 110 100 111

So the equivalent binary number is 110100111 Thus (647)8 = (110100111)2

Example : To convert F34A to binary.

Hexadecimal F 3 4 A Digits Binary 1111 0011 0100 1010 equivalent

So the equivalent Hexadecimal number is 1111001101001010 Thus (F34A)16 = (1111001101001010)2

Binary We can perform operations like addition, on Binary number systems just like any number system. Since binary number system consists of only two digits, the addition needs to follow some rules.

0+ 0 = 0 0 + 1 = 1

1 + 0 = 1

1 + 1 = 1 0 ( 0 with a carry 1)

NOTE: Also from the above rules we can derive that 1+1+1=11. Since : 1+1=1 0 So: 1 0+1=1 1 1 0 + 1 1 1

Examples: 1. Add 101 to 111

1 1 Carry

1 0 1

+ 1 1 1

1 1 0 0 So the answer is :1100

2. Add 1101 to 1011

1 1 1 Carry 1 1 0 1

+ 1 0 1 1

1 1 0 0 0 so the answer is :11000