Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
55 views18 pages

Data Representation Chapter - 2

This document discusses data representation in digital systems, focusing on various number systems including decimal, binary, octal, and hexadecimal. It explains the significance of these systems in computing, their positional value properties, and methods for converting between them. The binary system is emphasized as the most critical for digital technology due to its ease of implementation in electronic circuits.

Uploaded by

quntamtanush
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
55 views18 pages

Data Representation Chapter - 2

This document discusses data representation in digital systems, focusing on various number systems including decimal, binary, octal, and hexadecimal. It explains the significance of these systems in computing, their positional value properties, and methods for converting between them. The binary system is emphasized as the most critical for digital technology due to its ease of implementation in electronic circuits.

Uploaded by

quntamtanush
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 18
| Data Representation {y Wis Chapter 2.1 Introduction 2.4 Binary Addition 2.2. Digital Number Systems 2.5 Character/String Representation 2.3. Number Conversions 2.1 INTRODUCTION Digital techniques have found their way into innumerable areas of technology, but the area of automatic digital computers is by far the most notable and most extensive. As you know, a computer is a system of hardware that performs arithmetic operations, manipulates data, and makes decisions. In science, technology, business, and, in fact, most other fields of endeavour, we are constantly dealing with quantities; so are computers. Quantities are measured, monitored, recorded, manipulated arithmetically, observed, or in some other way utilized in most physical syste! In digital systems like computers, the quantities are represented by symbols called digits. Many number systems are in use in digital technology that represent the digits in various forms. The ‘most common ate the decimal, binary, octal, and hexadecimal systems. This chapter discusses these number systems and the physical representation of digits in computers. 2.2 DIGITAL NUMBER SYSTEMS In digital representation, various number systems are used. The most common number systems used are decimal, binary, octal, and hexadecimal systems. Let us discuss these number systems. 2.2.1 Decimal Number System (Bose 10) The decimal system is composed of 10 numerals or symbols (Deca means 10, that is why this system is called decimal system). These 10 symbols are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ; using these symbols as digits of anumber, we can express any quantity. The decimal system, also called the base-10 system because it has 10 digits, has evolved naturally as a result of the fact that man has 10 fingers. iz Le Ul ti‘i«~SD 24 COMPUTER SCIE! ITH PYTHON The decimal system is a postional-oniue system in which the value of a digit depends on ig Position. For example, consider the decimal number 729. We know that the digit 7 actually Represents 7 fhundreds, the 2 represents 2 tens, and the 9 represents 9 tits. In essence, thy 7 carries the most weight of three digits; its referred to as the most significant digit (MSD). The carries the least weight and is called the Jeast significant digit (LSD). Consider another example, 25.12. This number is actually equal to (2 tens plus 5 units plus 1 tenths plus 2 hundredths) ie, 2x10+5x1+ 1x 4,+2xqfq: The decimal point is used tg 10 Separate the integer and fractional parts of the number. More rigorously, the various positions relative to the decimal point carry weights that can be expressed as powers of 10, This is illustrated in Fig. 21 where the number 2512.1971 jg Represented. The decimal point separates the positive powers of 10 from the negative powers The number 2512,1971 is thus equal to 210° 45x10? 41x10" +2%10° 41x10 49x10 +7x 10-9 4110-4 In general, any number is simply the sum of the (cheats products of each digit value and its positional value. Base of a number system is also called radix, The squence of decimal Postional numbers goes as0,1,2,3,4, values» 10° 10? 10' «10 10? 402 107 104 (weights) 5,6,7,8,9, 10, 11,12,13, 14, ¢ Hee TY 15, 16, 17, 18, 19, 20, 21.... See after 9, cach successive SE a eae number is a combination of a i t two (or more) (unique) so decimal iso symbols of this system pars 2.2.2 Binary Number System (Base 2) Unfortunately, the decimal number system does not lend itself to convenient implementation in digital systems. For example, itis very difficult to design electronic equipment so that it can work with 10 different voltage levels (each one representing one decimal character, 0 through 9). On the other hand, itis very easy to design simple, accurate electronic circuits that operate with only two voltage levels. For this reason, almost every digital system uses the binary number system (base 2) as the basic number system of its operations, although other systems are often used in conjunction with binary. In the binary system there are only two symbols or possible digit values, 0 and 1. Even so, this base-2 system can be used to represent any quantity that can be represented in decimal or other number systems. The binary system is also a positional-value system, wherein each binary digit has its own value or weight expressed as a power of 2. This is illustrated in Fig. 2.2 Figure 2.1. Positional values in decimal numbers. Here, placestotheleft ofthe postonal 93 binary point (counterpart of values —» the decimal point) are posi- ge go gt ge pe gt + + + + + + + 0 tive powers of 2 and places 18/2 oes orb anton to the right are negative z ; + powers of 2. The number MsB ea Ls 1010.0101 is shown repre- (Most Significant Bit) point: (Least Significant 61) sented in the figure. Figure 2.2 Positional values in binary numbers. Chapter 2 : DATA REPRESENTATION 25 To find the decimal equivalent of above shown binary number, we simply take the sum of the products of each digit value (0 or 1) and its positional value 10100101, = (1x 23) + (0x 22) + (1x 2!) 4 (0% 2°) (0x2!) + (1x27) +(0x2 ) 41x24) 84+042404040.25 +04 0.0625 = 10.3125 5 Notice in the preceding operation that subscripts (2 and 10) were used to indicate the base in which the particular number is expressed. This convention is used to avoid confusion whenever more than one number system is being employed, In the binary system, the term Binary digit is often abbreviated to the term bit, which we'll use henceforth, As you see in Fig, 2.2, there are 4 bits to the left of the binary point, representing the integer part of the number, and 4 bits to the right of the binary point, representing the fractional part. The leftmost bit carries the largest weight and hence, is called the most significant bit (MSB). The rightmost bit carries the smallest weight, and hence called least significant bit (LSB). The sequence of binary numbers goes as 00, 01, 10, 11, 100, 101, 110, 111, 1000, - -- ---. The binary counting sequence has an important characteristic. The unit's bit (LSB) changes either from 0 to 1 or 1 to 0 with each count. The second bit (two's (2') position) stays at 0 for two counts, then at I for two counts, then at 0 for two counts, and so on. The third bit (four’s (2?) position) stays at 0 for four counts, then at 1 for four counts, and so on. The fourth bit (cight’s (2°) position) stays at 0 for eight counts, then at 1 for eight counts. If we wanted to count further we would add more places, and this pattern would continue with 0s and 1s alternating in groups of 2%-1. 2.2.3. Octal Number System (Base 8) The octal number system is very important in digital computer work. The octal number system has a base of eight, meaning that it has eight unique symbols : 0, 1, 2, 3, 4,5, 6, and 7. Thus, each digit of an octal number can have any value from 0 to 7. The octal system is also a posi- tional value system, wherein each octal digit has its own value or weight expressed as a power of 8 (see Fig. 2.3). The places to the left of the octal point (counter-part of decimal point and binary point) are positive powers of 8 and places to the right are negative powers of8.The s si number 3721.2406 is shown fate" gpg gt gp! og? sgt represented in the figure. (san) = snd 2s CL + + + + + + + + jecima 2 = aie | pevin [mes [step a ae t equivalent of above shown octal number, simply take the sum of products of each Octal point digit value and its positional Figure 2.3. Positional values in Octal numbers. value : 3721.2406g = (3x 8°) + (7x 87) +(2% 8!) -+(1 x8") +(2x 81) +(4x8) +(0x2 >) +(6x8™) = 3x 512 +7 x 64 42x B+1x1+2% 0,125 +4 x 0.015625 +0 +6x 0.000244 . = 1536 +448 +16 +1 + 0.25 +:0.0625 + 0 + 0.001464 = 2001.313964 The sequence of octal numbers goes as 0, 1, 2,3, 4,5, 6,7, 10, 11, 12, 13, 14, 15, 16, 17, 20, 21, 22... See each successive number after 7 is a combination of two or more unique symbols of octal system. a 26 COMPUTER SCIENCE WITH PYTHOy a 2.2.4 Hexadecimal Number System (Base 16) ‘The hexadecimal system uses base 16. Thus, it has 16 possible digit symbols. It uses the digi. through 9 plus the letters A, B,C, D, E, and F as the 16 digit symbols. Just like above discussed systems, hexadecimal system is also a positional-value system, when each hexadecimal digit has its own value or weight expressed as a power of 16. (see Fig, 24) 1) digit positions in a hexa- decimal number have weights | as shown in Fig. 2.4. Weights 16? | 16° | 16 | 16? | 167 | 167 ee «| Following table 2.1 shows the * relationships between hexa- eer decimal, octal, decimal and ee ae Figure 2.4 Positional values in hexadecimal numbers Table 2.1 Relationship between Various Number Systems | Hexadecimal |_Octal_| Decimal | Binary Hexadecimal | Octal _| Decimal | Bh 0 0 0 ‘0000 8 10 8 1000 1 1 it oor 9 u 9 1001 2 2 2 010 A 2 10 1010 3 3 3 oon B 13 u tou 4 4 4 100 ic 14 2 1100 5 5 5 o10L D 15 13 1101 6 6 6 ono E 16 4 1110 @ z Zz oun i 7 15 mu Note that each hexadecimal digit represents a group of four binary digits. It is important to remember that fiex (abbreviation for hexadecimal) digits A through F are equivalent to the decimal values 10 through 15. Applications of Hexadecimal Number System The hexadecimal number system is used in computers to specify memory addresses (which are 16-bit or 32-bit long) e.g., a memory address 1010110101011 is a big binary address but with hex it is D6AE, which is easier to remember. Another application of hexadecimal number system is to represent colour codes e.g. (FF, FE, FF) represents White in RGB value and (80, 80, 80) represents Grey in RGB value. 2.3 NUMBER CONVERSIONS The binary number system is the most important one in digital systems as it is very easy to implement in circuitry. The decimal system is important because it is universally used to represent quantities outside a digital system. In addition to binary and decimal, octal and hexadecimal number systems find widespread application in digital systems. These number systems (octal and hexadecimal) provide a efficient means for representing large binary numbers. As we shall see, both these numbe systems have the advantage that they can be easily converted to and from binary. Chapter 2 : DATA REPRESENTATION. 27 Ina digital system, three or four of these number systems may be in use at the same time, so that an understanding of the system operation requires the ability to convert from one number rem to another. This section discusses how to perform these conversions. So, let us discuss them one by one, 2.3.1 Decimal-to-Binary Conversion The common method of converting decimal to binary is repeated-division method. In this method, the number is successively divided by 2 and its remainders recorded. The final binary result is obtained by assembling all the remainders, with the last remainder being the most significant bit (MSB). 542 ind S Wotiggg—~ 2+ 2 ea sed 4 - ; a Goma Keep dividing quotient until you get 0. It can be written as : =25] 5 Remainders ay 2 1 e atte 0: 0 1 ‘Then write the remainders in last-to-first order. It means 5 of decimal number system is equal to 101 in binary system 549 =101. Consider another example 2 i Remainders 2 5 1 2 oh 1 2 1 0 => My =1011. fi 10 2 Let us consider some examples now. EXAMPLE Convert 43,9 to binary using repeated division method. SOLUTION Repeated Division 2 2 Remainders ‘ou| Sama 1 _LSB (Least Signifeant it) 2 10 1 Sine aaa 0 Wit inthis 2) 2 q oe Reading the remainders from 2 a. 0 the bottom to the top, 0 1 MSB (Most Significant Bit) 434) =101011, 28 COMPUTER Scitce wy CAMELS Ds conmnaay SOLUTION TH Pry Ww 40 binary using repeated division metho, Remainders eG 0 LSI ss iB Z MSB the result is : 200, =11001000, mpute 852 the conversion as depicted through cae following example. (As you enn see that this is just ai nother way of representing the x 4, Leas sigifcant ne (usa epeated division.) EXAMPLE Convert 83 repeated division method, SOLUTION (See on the right) Q- Quotient and R~Remainder So t0 binary using 85,9 = 1010101, 1-Most significant bit (MsB) Converting Fraction from Decimal to Binary Fora fractional decimal number, you can convert it to binary as : abe. xyz (where a, b, ¢ x, y, z are digits) abcas repeated division covered above and .xy2 using repeated as iplication as illustrated below. multiplication as illust a ; For instance, if you have 5.35, then convert 5 using repeated Aivision as covered earlier and 0,35 as given in adjacent box. ohn 2= 080 0 Keep multiplying the fractional part with 2 and take out the non-fractional part : (repeated multiplication) 0.80%2=1.6 Ay Consider the following example. eee Chapter 2 : DATA REPRESENTATION, 29 EXAMPLE EY Convert 4.8125 decimal number into SOLUTION 4—non fractional part using repeated division 0.8125 — fractional part using repeated multiplication. Remainders 0.8125 x 2 = 1,625 0.625 x 2 = 1.250 | 0.250 x 2 =0.5 | 05%2=1.0 Thus 4.8125,) = 100.1101, 2.3.2 Binary-io-Decimal Conversion Roe The binary number system is a positional system where each binary digit (bit) carries a certain weight based on its position relative to the LSB. Any binary number can be converted to its decimal equivalent simply by summing together the weights of the various positions in the binary number which contain a 1. To illustrate, consider a binary number 11011, 1] 1] of a] 1] inary {Add positional weights for all 15, > 2442940421429 =164+84+2+1 =27 1p (decimal) Let's try another example with a greater number of bits ie, 10110101, 1] 0} 1] 1) of ajoja ‘Adding positional weights ofall 1's > 27 40425 +24 +0427 +042" =181i9 Note that the procedure is to find the weights (ie, powers of 2) for each bit position that contains a 1, and then to add them up. Also note that the MSB has a weight of 2” even though it is the eighth bit; this is because the LSB is the first bit and has a weight of 2°. ‘The above method will always provide the correct decimal representation of a binary number. ‘There is a second method, called the dibble-dobble method, that will also provide the solution. To use this method, start with the left-hand bit. Multiply this value by 2, and add the next bit to the right. Multiply the result value by 2, and add the next bit to the right. Stop when the binary point is reached. To illustrate to through the following two examples, 11011, (binary) 110100, Copy down the leftmost bit : 1 ‘The leftmost bit : Multiply by 2, add next bit (2x1) + 1=3. Multiply by 2, add next bit (2x 1) + 1=3 Multiply by 2, add next bit x3) +0 =6 Multiply by 2, add next bit x3) +0 Multiply by 2, add next bit (2x6) +1=13 ; — Multiply by 2, addnextbit @x6)+1 Multiply by 2,add next bit 2x13) +1=27 Multiply by 2, add next bit (2x 13) + 0 =26 Multiply by 2, add next bit 110100, MOM, =274o 2G (2x26) + 0 =52 30 ional Part Converting Fracti number 82 P pqs a COMPUTER SCIENCE WITH PYTHoy ~H (ohare py #6, bareibils) converted as ‘A fractional binary TPO NEA? ‘ peer nge ess s converted as eg 100.1101 i oe pina) 1e2? 40x25 4 1x24 1x22 40x aarororded rota = 4405 0.25 + 0.0625 = 4.8125 100.1101) = 4.812510 jersion Decimal: to-Octal Conv ‘A decimal integer can be converte we used in the decimal-to-binary example is shown below 266 33. 4 0 dt cor Remainders 2 bb 1 4 Reading up, 2669 = 412s 2.3.4 Octal-to-Decimal Conversion ‘An octal number, then, can be easily converted to its decimal equivalent by multiplying each o octal by using the same repeated-division method thay aversion, but with a division factor of 8 instead of 2. An Note that the first remainder becomes the least significant digit (LSD) of the octal number, and the last remainder becomes the most significant digit (MSD). To convert to decimal system, every number system follows this rule Multiply each digit with base positional weight /e., for anumber ijk-Imn Binary to decimal=/ 22+ jx2! +k x2 41x27 +m x27 40 x2? Octal to decimal = x84 j x8! +k x84 /x8 1 +m x87 +0 x8 me Hexadecimal to decimal eie16 j 16 ek x16! +1 x67 4m x18? + x16? octal digit by its positional weight. For example, 372g =3x (8) +7 x (81) +2* (8°) Another example: 24.65 =2%(81) +4 x (8°) +6x(8 at 3x 64+7x8+2x1 = 25019 = 20.7519 2.3.5 Octal-to-Binary Conversion The primary advantage of the octal number made between binary and octal numbers. Th converting each octal digit to its 3-bit binary equival as indicated in Table 2.2. Table 2.2 Binary Equivalents of Octal Digits o 1 000 001 system is the ease with which conversion can be e conversion from octal to binary is performed by Jent. The eight possible digits are converted 5 101 6 110 z m1 2 10 3 ou 4 100 Octal Digit Binary Equivalent Using these conversions, any octal number is converted to binary by individually converting each digit. For example, we can convert 472, to binary ‘As another example, consider converting 5431 to binary : using 3 bits for each octal digit as follows : a Gi 3 i . e o + + + + i { A 101100 oll 00 = Sst ‘Thus, 5431, =101100011001,. Hence, octal 472 is equivalent to binary 100111010, Chapter 2 : DATA REPRESENTATION 31 2.3.6 2.3.7 Thesame process applies equally on fractions. For example, ET RAR ae The octal to binary conversion takes Sg= ¥ + place using 3-bit sub- stitution for O11 * 001 ‘each octal character. Because 2? =8, thus an octal number 3g = 011.001, takes 3-bits to represent itself, Binary-to-Octal Conversion Converting from binary integers to octal integers is simply the reverse of the foregoing process. The bits of the binary integer are grouped into groups of three bits starting at the LSB. Then each group is converted to its octal equivalent (Table 2.2), To illustrate, consider the conversion of 100111010, to octal i ob eh ty J J 4 4 7 2, Sometimes the binary number will not have even groups of 3 bits. For those cases, we can add ‘one or two 0s to the left of MSB of the binary number to fill out the last group. This is illustrated below for the binary number 11010110. Cee o 20) wed 0 added here to make “LS l 1 t i group of 3 bts aa, ee 3 2 6 Note that a 0 was placed to the left of the MSB in order to produce complete groups of 3. The same process applies on fractions. But after the binary point, zeros are added to the right. For example — 10110.0101, = 010 d 10 2 010 100 ~ aie 2 A 2 ert cided here 10110.0101, = 26.24, make it a group of 3 bits Note that, after the binary point, the groups of 3 bits are made starting from left-to-right. That is. why, we added two zeros to make a group of three bits as the last group had only 1. Decimal-to Hex Conversion Recall that we did decimalto-binary conversion using repeated division by 2, and decimal-to-octal using repeated division by 8. Likewise, decimal-to-hex conversion can be done using repeated division by 16. For example, To convert 4234 to hex, : Similarly, to convert 21449 to hex, Remainders i Remainders te| 423 i 16 |__214 As [ite aad, et a 16 | a3 . 16 1 A = eal eat ea al eang Eee Sees 0 D 30 = De) Reading up, 4239 =147 15 Reading up, 214 1 = D6, Note that any remainders that are greater than 9 are represented by letters A through F. 32 “4 2.3.8 Hex-to-Decimal Conversion A hex number can be converted to its decimal equivalent by using the fact that eac position has a weight that is a power of 16. The LSD has a weight of 16” has a weight of 16! conversion proces A hex gi ml Ce nate higher gf 6, the next higher digit has a weight of 16” =256, and so on s is demonstrated in the examples below : + The 16? 45x16! 46x16" =768 + 80+ 6 = 854 19 16? +10%16' +15x 16° =512+160-+15 = 687 yp Note that in the second example the value 10 was substituted for A and the value 16 for F in th conversion to decimal. To convert a fractional number, 56.084 =5% 16" + 6x16" +0x 16“) +8x16 * =80+6+ 048 / 256 = 86 + 0.03125 = 86.03125,9 2.3.9 Binary-to-Hex Conversion Binary numbers can be easil y converted to hexadecimal by grouping in groups of four start at the binary point. EXAMPLE [El Convert 1010111010, to hexadecimal EXAMPLE FB) Convert 1010171001017, fo hex SOLUTION ESOLUTION Groups in fours (inserting zero Group in fours 0010,1011,1010 before MSB or in the end, wherever required) ce Convert each number eae 1010, 1110 . 0101, 1100 ee oe Thus, the solution is 2BA. Rene cae 10101110.010111, = AE.SC,, 2.3.10 Hex to Binary Conversion Like the octal number system, the hexadecimal number system is used primarily as “shorthand” method for representing binary nur-bers. It is a relatively simple matter to conver ahexnumber to binary. Ench hex digits converted its 4-bit binary equivalent (Table 2.1). Thi is illustrated below for 9F2,, OF2i5= 9 E 2 Similarly, 3A6,,= 3 A 6 Y + + + + 4 DO eT aa 10) 0011 1010 o110 = 100111110010, =001110100110, Consider another example OBR SCie= 26) Ber Fanos) = 1c ee eee v bovovoe Hex to binary conversion takes place Us 0011 1011 1111 0101 1100 4-bit substitution for each hex characte Because 2=16, thus a hexadecin =001110111111.01011100, hue takes is epee eh Converting from Any Base to Any OTHER Base As demonstrated in earlier examples and the table below, there is a direct corresponden between the number systems : with three binary digits corresponding to one octal digit sa (@ From the complete binary number, we shall create groups of 4 binary di decimal point. COMPUTER 5% Bits aroun (it) Convert each 4-digit-binary group to equivalent hex digit. 110 4 100 O11 0111 1011 1010 0011. ewe bat7 7G 4 101 111 000 100 11101110100011.101111000100 , 1011 1100 0100 Octat Pie 6 Binary 111101 756435704, Binary Hexadecimal 7 A 756435704, = 7BA3.BC4,, ie C4 After learning about various digital number systems, let us talk about binary addition, 2.4 BINARY ADDITION err 1 1 What are the bases of decimal, octal, binary and hexadecimal systems ? 2 What is the common property of decimal, octal, binary and hexadecimal umber systems ? 3. Complete the sequence of following Binary numbers = 100, 101, 110, 4. Complete the sequence of. following octal numbers : 525, $26, 527, 5 Complete (he Segue e cuneteg hexadecimal numbers : 17, 18, 19, 6. Convert the following binary numbers to decimal and hexadecimal : (@) 1010 (6) 111010 (@) 101011111 (@) 1100 (e) 10010101 (f) 11011100 7. Convert the following decimal numbers to binary and octal : (a) 23 (#) 100 (45 (a) 19 (6) 121 (f) 161 8 Convert the following hexadecimal numbers to binary : (a) A6 (b) A07 (0) TABA (d) BE (c) BC9 (f) 98¢8 9. Convert the following binary numbers to hexadecimal and octal : (o) 10014011201 (6) 1111011101011011 (6 1101011101011 (¢) 1010110110111 (e) t0110111011011 aanousio1011 ALUs don’t directly work upon decimal numbers ; Tathe they process binary numbers as a computer can understan, only binary numbers. There are five basic cases for binan addition that must be understood before going on. These are. Case1: 0+0=0 ie, addition of two binary 0s (zero) results into: binary 0 (zero). Case 2: 0+1=1 ie, addition of a binary 0 (zero) and a binary | (one) results into binary 1 (one). Case3: 1+0=1 ie, addition of a binary 1 (one) and a binary ( (zero) results into binary 1 (one) Case 4: 1+1=10 ie, Binary 1 + Binary 1 equals Binary 10. Or we ca say that in binary numbers, one plus one equal zero (0), carry one (1). Case 5: 1+1+1=11 ie, Binary 1 +Binary 1 + Binary 1 equals Binary 1 carry Binary 1. Let us summarize these rules 0+0=0 [0 with carry J 141+1= 11 [1 with carry Chopter 2 : DATA REPRESENTATION, Let us now perform binary addition on bigger binary numbers. The binary numbers are also added column-by-column just like | decimal numbers. Also, the way results larger than largest decimal digit are carried-over, i binary addition, results larger than 1 are also carried over. For example, 5 Decimal Addition This is carried over as +7 =12 4 <—— which is more than 9, lence 15 carried over 27 42 Similarly, Binary Addition will be ee 4144 1411 Equivalent of 15 one quivalent of 15,0) (Equivalent of 270) 101010 Equivalent of 42,5) Let us perform another addition, step-by-step for 11100 +11010 Start with the least significant column i,, the | right most column to get 11100 +11010 0 Inall examples, 0 + 0 gives 0. In this case, 1+O results in 11100 +11010 Soeee = (cary a 0110 ‘ ; ‘As you see, 1+1 produces 10 ie., 0 with a carry of 1. Finally, the last column gives 1<— Carries 11100 +11010 110110 Here, 1+1+1 (previously generated carry) results in 11, recorded as 1 with a carry to the next higher column. EXAMPLE [Ey Add the binary monbers 01010111 and 00110101. SOLUTION If you add the bits column by column as earlier explained you will get 4440 144 <— Carries o1010111 +00110101 10001100 | EXAMPLE BOO) Add the binary numbers 1011 and 110. = SOLUTION 41 +—— Carries 1011 + 110 10001 Next, add the bits of the second column? example BEN Add binary numbers 11110 and 11. (second from right) as follows : 11100 #11010 11111 Se This time, 0 +1 gives The addition in third column gives 11100 +11010 ae er 411 <— Caries 11110 ir 100001 | EXAMPLE [Add binary numbers 11.01 and 101.11. = SOLUTION 111 1 +— Caries 11.01 101.11 1001.00 ae ; COMPUTER SCIENCE WITH ngs F 36 SENTATION handle letters and other ‘yb, to ih oo that represent letters of the a i, numbers. Have you ever j a, S pressed on the keyboard 7.8 ding scheme is a predetermined set of cogq »mbol. When @ key is pressed on the keyboa from the encoding scheme. Computer, then oi er/letter/symbol pressed, ding scheme and gets the numb yheme is very crucial in @ computer system. Most pop le, ISCII etc CHARACTER/STRING vo oe tio erical data, i Sie computer should recog" : snarks, and other 5 ygnizes whiel coding sche number and sy code for that key In punetuation how a computer Teco! possible through an en recognized latter, then sends the 4 code in the enco ncoding sc ASCII, Unicod each keyboard the receive ‘Thus the role of ane encoding schemes are 2.5.) ASCII Code : The most widely used alphanumeric. encoding scheme, the Beis Sees Coe Information Interchange (ASCH), is used in nost microcomputers and minicomPuters a ry mainframes, The ASCII code (pronounced viaskee”) is a 7-bit code, and so it has 2 = possible code groups. This is more than ‘enough to represent all of the standard keyboa Rraracters as well as control functions such as the (RETURN) and (LINEFEED) functg sane 5 ahows a partial listing of the ASCII code. In addition the binary code group fore ceorectes the table gives the octal and hexadecimal equivalents. Table 2.5. Partial isting of ASCII Code Character |_7-Bit ASCH_| Decimal | Octal Hex Character _ Tpit Ascu__| Decimal | Octal Hex A 100 0001 65 101 41 ne 101 1001 89 131 59 (eee 100 0010 | 66 102 | 42 Zz 101 1010 90. 132_| 5A leases yoo oo. | 67 103 | 43 0 11 0000 48 (060 2 p | roc | 6 | 14 | 4 1 cncon | 49 | oo | 3 E 100 0101 6 105 45 2 011 0010 50 062 32 F tooo110 | 70 106 46 3 011 0011 51 063 33 6 | mom | a | wm | 7 4 ooi0 | 52 | oo | 3 BH | 1100 | 2 | m0 | 4 5 oncin | 53 | 06 | 3 © 100 1001 B 11 49, 6 011 0110 5a 066 36 T 100 1010 7h 112 4A e O11 0111, 55. 067 37 «k | won | 7% | us | a 8 o111000 | 36 | 07 | 38 t | imo | 7% | m4 | 4c 9 our | 7 | on | » ¥ ta a i me 4D blank 010 1000 32 040 20 46 a | ee | aes Paro oslo | | r a 80 120 - es | ee oe ee R tor oo10 | 82 12 | Be 2 10 1010 2 i 2 | 052 | 20 $ 101 0011 83 123. ‘53 2 ma at e Bee 2g ng toro10 | 84 124 5 L ae s . 2 u 101 0101 85 15 55 ° ot se Ge a Yo | som | a | ue | os = i | 101 0011 87 oh elise | | we |e ee |B scale = EED)| 000 1010 10. O12 oA Chaplor 2 : DATA REPRESENTATION. EXAMPLE The following is a message encoded in ASCH code. What is the message ? 1001000 1000101 1001100 1010000 SOLUTION Convert each 7-bit code to its hex equivalent, The results are 48 45 AC 50 Now locate these hex values in Table 2,7 and determine the character represented by each, The results are tBu The ASCII code is used for the transfer of alphanumeric information between a computer and input/output devices such as video terminal it internally to store the information that an operator type: or printers, A computer also use: at the computer's keyboard The following example illustrates this. EXAMPLE BEY An operator is typing in a BASIC program at the keyboard of a certain micro-compiter, The computer converts each keystroke into its ASCH code and stores the code in memory. Determine tite codes that will be entered into memory when the operator types in the following BASIC statement : GOTO 25 SOLUTION Locate each character (including the space) in Table 2.7 and record its ASCII code, ‘The main advantage of ASCII is its simplicity — it uses one byte to represent one character | ene Os There is extended ASCII that uses 8 bits to represent - Jou various characters. It can represent 256 characters, as T 1010100 opposed to 128 characters of ASCII. % rie Apart from ASCII there are other systems that are also used to represent various symbols. | Space) oxconeon) In the following lines, we are talking about some of these — 2 110010 ISCII and Unicode. 7 ee 2.5.2. |SCIl Code With the advent of computerization considerable work has been undertaken to facilitate the use of Indian languages on computers. These activities were generally limited to specific languages and were independent exercises of various organizations, thus, making data-interchange impossible. Insuch a scenario, it was important to have a common standard for coding Indian scripts. In 1991, the Bureau of Indian Standards adopted the Indian Standard Code for Information Interchange (ISCI), the ISCII standard that was evolved by a standardization committee. This is an eight-bit code capable of coding 256 characters. ISCII code retains all ASCII characters and offers coding, for Indian scripts also. Thus, itis also called Indian Scripts Code for Information Interchange. All GIST products are based on ISCIL. Also ISCII has been used by IBM for PC-DOS, Apple for ILK, and by several other companies that are developing products and solutions based on this representation. Also ISCI has been made mandatory for the data being collected by ; organizations like The Election Commission, and for projects as Land Records Project etc. This standard does not only apply to the Devanagari script , but also to the Gurmukhi, Gujarati, Oriya, Bengali, Assamese, Telugu, Kannada, Malayalam and Tamil script. Because the structure of these scripts is so similar that a single coding can be applied to all of them, immediately providing transliteration between the scripts. 38 Some of the ISCH. versions Devnagari Sci script © Sc 25.3 Unicode You have leamt about These encoding sche; encoding scheme th, Sneoding scheme. Unicode is the These encoding systems also number for two different SSPra J. Encode “INDIA” and “MARCHING” into ASCII codeform. 2 ASCII code is ___ bit code, extended ‘ASCIL is __ bit code and Unicode is —— dit code. 3. What is the use of ASCII code and Unicode ? 4. What 3s the full form of ASC and Be rtinkole | 3 Name two Indian languages in Unicode ___ along with their script names. * for different scripts maa nS 4 8lobal village thanks to modem technolo, resent all the known 1; answer, at could rep: conflict with one another. That is, two enco characters, example, the character code OFF rep same code represents Sin Russian COMPUTER SCIENCE Wan, p ” are being given below. ? aneed was being felt foray anguages characters through on dings can use the sam: or use different numbers for # the same character. Fag resents ¥ in west European code Page IS08859-1, while th code page 1251. Any given computer (especially servers) needs to Suppot many different encodings; yet whenever data is passd between different encodings or platforms, that data aay Tuns the risk of corruption. Encoding Terminology Before we proceed further, it is important to discuss ft basic terms related to encoding. Code Space 4 It refers to all the codes that an encoding scheme usa! represent characters. eg., ASCII encoding scheme hs! code space from 0 to 127 (0x 0 to 0x 7F). | Chapter 2 : DATA REPRESENTATION 39 Code Point The code point refers to a code (from a code space) that represents a single character from the character set represented by an encoding scheme, e.g., 0x41 is one code point of ASCII that represents character ‘A’. ASCII has 128 code points while Unicode has 1,112,064 code points. Unicode Encoding Schemes Unicode defines multiple encoding systems to represent characters. These are UTE-8, UTF-16 and UTF-32. Let us discuss about these Unicode encoding schemes. The character encoding scheme reflects the way the coded character set is actually mapped to bytes in form of binary code (machine intelligible code) for manipulation in a computer. 2.5.3A UTF-8 (Unicode Transformation Format)-8 UTF-8 isa variable-width encoding that can represent every character in Unicode character set. In other words, it can encode each of the 1,114,112 code points in the Unicode character set. ‘The code unit of UTE-S is 8 bits, called an octet. UTF-8 can use 1 to maximum 6 octets to represent code poinis depending on their ia size, although till now it has used upto 4 octets to represent any 75. jg another brillant idea by character. Ken Thompson (one of the UTF-8 is a type of multi-byte encoding. Sometimes you only use “eaters of UNIX). 8 bits to store the character, other times, 16 or 24 or more bits. Unicode codepoints are often written as U+ ¢.g., U+0041 represents letter ‘A’. UTES is a variable length encoding scheme. That is, it uses different number of bytes or octets (set of 8 bits) to represent different characters. Following Table 2.6 gives an idea about how many octets will be used to represent a Unicode code point. Tlable 2.6 Unicode Code Points and No. of Octets used in UTF-8 Unicode Code Points Unicode Code Points Number of | (in decimal) (in Hexadecimal) Octets used U-0 - U-127 (G40 to UH07F) 1 octet (8 bits) U-128 - U-2047 (U+80 to U+7FF) 2 octets (16 bits) U-2048 — U-65535 (U+800 to U+FFFR) 3 octets (24 bits) V-65536 — U-2097151 (U+10000 to UHFFFFF) _| 4 octets (32 bits) 2.5.38 UTF-32 UTF-32isa fixed length encoding scheme that uses exactly 4 bytes to represent all Unicode code points. That is, it directly stores the binary code of any Unicode code point in 4 bytes. Consider these examples © Symbols $ [Unicode code point : U + 0024, Binary code : 00100100} Chapter 2: DATA REPRESENTATION Assignments 10, "1 12, 13. 4. Type eSxagveepe 10. i. 13, 4. 15. 16. er Questions/Conceptual Questions mber systems used by computers ? What is the use of Hexa lecimal number system on computers ? What does radix or base signify ? What is the use of encoding schemes ? Discuss UTF-8 encoding scheme. How is UTE-8 encoding, scheme different from UTF-32 encoding, scheme ? What is the most significant bit and the least significant bit in a binary code ? What are ASCII and extended ASCII encoding schemes ? What is the utility of ISCII encoding scheme ? What is Unicode ? What is its significance ? What all encoding schemes does Unicode use to represent characters ? What are ASCII and ISCII ? Why are these used ? What are UTF-8 and UTF-32 encoding schemes. Which one is more popular encoding scheme ? What do you understand by code point ? What is the difference between fixed length and variable length encoding schemes ? B : Application Based Questions Convert the following binary numbers to decimal (a) 1101 (6) 111010 (©) 101011111 Convert the following binary numbers to decimal : (a) 1100 (b) 10010101 (c) 11011100 Convert the following decimal numbers to binary (23 (100 (9 145 (a) 0.25 Convert the following decimal numbers to binary @19 (by 122 (©) 161 (a) 0.675 Convert the following decimal numbers to octal @i9 12 (©) 161 (a) 0.675 Convert the following hexadecimal numbers to binary: (a) A6 —_(b) AO7 (0) TABS Convert the following hexadecimal numbers to binary: (a) 23D —_(b) BC9 (9 98c8 Convert the following binary numbers to hexadecimal : (a) 10011011101 (® Wno1t101011011 (2) MoLo1 1010111 Convert the following binary numbers to hexadecimal : (a) 1010110110111 (1110111011011 -—_@) 110101100 Convert the following octal numbers to decimal : (a)257 (6) 3527 (c) 123. (a) 605.12 Convert the following hexadecimal numbers to decimal: (a) A6-_—_(b) AI3B_() 345. Convert the following hexadecimal numbers to decimal: (a) E9 —_(b) 7 CA3 Convert the following decimal numbers to hexadecimal: (a) 132. (b) 2352. (¢) 122 (d) 0.675 Convert the following decimal numbers to hexadecimal : (a) 206 (b) 3619 Convert the following hexadecimal numbers to octal : ()38AC —(&) 7FD6 (9 ABCD Convert the following octal numbers to binary: (a) 123. (b) 3527 _(¢) 705 COMPUTER SCIENCE WITH Prtyo, N numbers to binary Convert the following octal ( 7642 (0) 7015 (93576 (a) 705 Convert the following binary numbers 0 octal : (o) 1101100001 qb 110110101 ary numbers to octal (¢) 1010111 (@ m010 following bin (v) 10101100 Convert the (a 11001 Add the following binary numbers + ( 10110111 and 1100101 (ii) 110111.110 and 11011101.010 Given that A’s code point in ASCII is 65, “A! in ASCII? (and what's its hexadecimal (i 110101 and 101111 () 1110.110 and 11010.011 ‘and a’s code point is 97. What is the binary representation || representation). What is the binary representation of a ASCH? Convert the following binary numbers to decimal, octal and hexadecimal numbers. @ 100101.101 (i) 10101100. 01011 (ii) 1010 (i) 10101100.010111

You might also like