65
Number System and Programming Languages NOTES Self-Instructional Material 145 UNIT 2 NUMBER SYSTEM AND PROGRAMMING LANGUAGES Structure 2.0 Introduction 2.1 Unit Objectives 2.2 Number Systems 2.3 Bits and Bytes 2.4 Binary Number System 2.5 Decimal Number System 2.6 Octal Number System 2.7 Hexadecimal Number System 2.8 Conversion from One Number System to the Other 2.8.1 Binary to Decimal Conversion; 2.8.2 Decimal to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5 Octal to Decimal Conversion; 2.8.6 Decimal to Octal Conversion 2.8.7 Octal to Binary Conversion; 2.8.8 Binary to Octal Conversion 2.8.9 Hexadecimal to Binary Conversion 2.8.10 Binary to Hexadecimal Conversion 2.8.11 Hexadecimal to Decimal Conversion 2.8.12 Decimal to Hexadecimal Conversion 2.8.13 Hexadecimal to Octal Conversion 2.8.14 Octal to Hexadecimal Conversion 2.9 Representation of Characters 2.10 Integers and Fractions 2.10.1 Floating Point Representation of Numbers 2.11 Binary Arithmetic 2.11.1 Binary Addition; 2.11.2 Binary Subtraction 2.11.3 Binary Multiplication; 2.11.4 Complement Arithmetic 2.11.5 Signal Binary Number Representation 2.12 Computer Languages and Its Types 2.13 Generation of Computer Languages 2.14 Character Codes 2.15 Summary 2.16 Key Terms 2.17 Answers to ‘Check Your Progress’ 2.18 Questions and Exercises 2.19 Further Reading 2.0 INTRODUCTION A mathematical tool used to count and measure is known as a number. The moment we hear the ‘term’ numbers, our mind begins to picturize digits like 0, 1, 2, 3, etc.

Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

Embed Size (px)

Citation preview

Page 1: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

Number System andProgramming Languages

NOTES

Self-Instructional Material 145

UNIT 2 NUMBER SYSTEM ANDPROGRAMMINGLANGUAGES

Structure2.0 Introduction2.1 Unit Objectives2.2 Number Systems2.3 Bits and Bytes2.4 Binary Number System2.5 Decimal Number System2.6 Octal Number System2.7 Hexadecimal Number System2.8 Conversion from One Number System to the Other

2.8.1 Binary to Decimal Conversion; 2.8.2 Decimal to Binary Conversion2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary2.8.5 Octal to Decimal Conversion; 2.8.6 Decimal to Octal Conversion2.8.7 Octal to Binary Conversion; 2.8.8 Binary to Octal Conversion2.8.9 Hexadecimal to Binary Conversion

2.8.10 Binary to Hexadecimal Conversion2.8.11 Hexadecimal to Decimal Conversion2.8.12 Decimal to Hexadecimal Conversion2.8.13 Hexadecimal to Octal Conversion2.8.14 Octal to Hexadecimal Conversion

2.9 Representation of Characters2.10 Integers and Fractions

2.10.1 Floating Point Representation of Numbers2.11 Binary Arithmetic

2.11.1 Binary Addition; 2.11.2 Binary Subtraction2.11.3 Binary Multiplication; 2.11.4 Complement Arithmetic2.11.5 Signal Binary Number Representation

2.12 Computer Languages and Its Types2.13 Generation of Computer Languages2.14 Character Codes2.15 Summary2.16 Key Terms2.17 Answers to ‘Check Your Progress’2.18 Questions and Exercises2.19 Further Reading

2.0 INTRODUCTION

A mathematical tool used to count and measure is known as a number. The momentwe hear the ‘term’ numbers, our mind begins to picturize digits like 0, 1, 2, 3, etc.

Page 2: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

146 Self-Instructional Material

Number System andProgramming Languages

NOTES

Numbers are used in everyday life for calculating even the smallest of things, andhas brought system to the world as a whole. Numbers are used everywhere byeveryone, in shops, offices, businesses, homes, etc.

This unit will discuss number systems, bits and bytes, binary number system,decimal number system, octal number system and hexadecimal number system.You will also learn about conversion from one number system to another,representation of characters, integers and fractions, computer languages and itstypes, generation of computer languages and character codes.

2.1 UNIT OBJECTIVES

After going through this unit, you will be able to:• Understand the various number systems• Perform conversions from one number system to another• Understand integers and fractions• Understand the various computer languages• Trace the history of computer languages

2.2 NUMBER SYSTEMS

A number represents a thought that refers to a precise amount of something.Numbers can be expressed in words, gestures and symbols. When expressed inwords, numbers are spoken out. Numbers are expressed through gestures using(usually) our hands. Numbers are expressed in symbols that can be written down.A number symbol is known as numeral. Hence, a number is a precise idea aboutan amount, which we form in our minds when we look at a numeral, hear it whenit is spoken or see it when it is signalled by hands.

On hearing the word number, we immediately think of the familiar decimalnumber system with its 10 digits; 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9. These numerals arecalled Arabic numerals. Our present number system provides modernmathematicians and scientists with great advantages over those of previouscivilizations, and is an important factor in our advancement. Since fingers are themost convenient tools nature has provided, human beings use them in counting. Sothe decimal number system followed naturally from this usage.

A number having base, or radix r, is a system that makes use of distinctsymbols of r digits. A string of digit symbols represent numbers. To find out thequantity represented by a number, it is essential that each digit be multiplied by aninteger power of r, and then the sum of all the weighted digits be formed. Anywhole number greater than one can be used as a base in building a numerationsystem. The number of digits in use will always be equal to the base.

Page 3: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

Number System andProgramming Languages

NOTES

Self-Instructional Material 147

There are four systems of arithmetic, which are often used in digital systems.These systems are:

1. Decimal2. Binary3. Hexadecimal4. Octal

In any number system, there is an ordered set of symbols known as digits. Collectionof these digits makes a number which in general has two parts, integer and fractional,and are set apart by a radix point (.). Hence, a number system can be representedas,

b̂N = 1 2 3 1 0 1 2 3 –Integer portion Fractional portion

... ...n n n ma a a a a a a a a− − − − − −⋅

where, N = A number

b = Radix or base of the number system

n = Number of digits in integer portion

m = Number of digits in fractional portion

an – 1 = Most significant digit (MSD)

a– m = Least significant digit (LSD)

and 0 ≤ (ai or a–f) ≤ ⋅ b–1

Base or Radix: The base or radix of a number is defined as the number ofdifferent digits which can occur in each position in the number system.

2.3 BITS AND BYTES

All data to be stored and processed in computers are transformed or coded asstrings of two symbols, one symbol to represent each state. The two symbolsnormally used are 0 and 1. These are known as BITS, an abbreviation for BInarydigiTS.

Let us now understand some commonly used terms.

BITS The smallest component used by a computer is the bit that holds oneof the two likely values.

Value Meaning 0 Off

1 On

A bit which is OFF is also considered to be FALSE or NOT SET; a bit whichis ON is also considered to be TRUE or SET.

Page 4: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

148 Self-Instructional Material

Number System andProgramming Languages

NOTES

Since a single bit can only store two values, there could possibly be only fourunique combinations as follows,

00 01 10 11

Bits are therefore, combined together into larger units so that they can holdgreater range of values.

NIBBLE A nibble is a group of 4 bits. This gives a maximum number ofsixteen possible different values.

24 = 16 (2 to the power of the number of bits)

BYTES Bytes are a grouping of 8 bits (two nibbles) and are often used tostore characters. They can also be used to store numeric values.

28 = 256 (2 to the power of the number of bits)

2.4 BINARY NUMBER SYSTEM

A number system that makes use of just two digits, 0 and 1 is called the binarynumber system. The binary number system is also known as a base two system.The two symbols 0 and 1 are known as bits (binary digits).

The binary system groups numbers by twos and by powers of two, shown inFigure 2.1. The word binary is derived from a Latin word which means two at atime.

Figure 2.1 Binary Position Values as a Power of 2.

The weight or place value of each position can be expressed in terms of 2,and is ����������� �� 20, 21, 22, etc. The least significant digit has a weight of 20

(= 1). The second position to the left of the least significant digit is multiplied by 21

(= 2). The third position has a weight equal to 22 (= 4). Thus, the weights are in theascending powers of 2 or 1, 2, 4, 8, 16, 32, 64, 128, etc.

The numeral 10two (one, zero, base two) stands for two, the base of thesystem.

In binary counting, single digits are used for none and one. Two-digitnumbers are used for 10two and 11two [2 and 3 in decimal numerals]. For thenext counting number, 100two (4 in decimal numerals) three digits are essential.After 111two (7 in decimal numerals) four-digit numerals are used until 1111two(15 in decimal numerals) is reached, and so on. In a binary numeral, everyposition has a value 2 times the value of the position to its right.

Page 5: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

Number System andProgramming Languages

NOTES

Self-Instructional Material 149

A binary number with 4 bits, is called a nibble and a binary number with8 bits is known as a byte.

For example, the number 10112 actually stands for the following representation:

10112 = 1 × 23 + 0 × 22 + 1 × 21 + 1 × 20

= 1 × 8 + 0 × 4 + 1 × 2 + 1 × 1

∴ 10112 = 8 + 0 + 2 + 1 = 1110

In general,

[bnbn – 1 ... b2, b1, b0]2 = bn2n + bn – 12n–1 + ... + b222 + b121 + b020

Similarly, the binary number 10101.011 can be written as

1 0 1 0 1 . 0 1 1

24 23 22 21 20 . 2– 1 2– 2 2– 3

(MSD) (LSD)

∴ 10101.0112 = 1 × 24 + 0 × 23 + 1 × 22 + 0 × 21 + 1 × 20

+ 0 × 2–1 + 1 × 2–2 + 1 × 2–3

= 16 + 0 + 4 + 0 + 1 + 0 + 0.25 + 0.125 = 21.37510

In each binary digit, the value increases in powers of two starting with 0 to the leftof the binary point and decreases to the right of the binary point starting withpower –1.

Why is Binary Number System used in Digital Computers?

Binary number system is used in digital computers because all electrical andelectronic circuits can be made to respond to the two states concept. A switch,for instance, can be either opened or closed, only two possible states exist. Atransistor can be made to operate either in cut-off or saturation; a magnetictape can be either magnetized or non-magnetized; a signal can be either HIGHor LOW; a punched tape can have a hole or no hole. In all of the above illustrations,each device is operated in any one of the two possible states and the intermediatecondition does not exist. Thus, zero can represent one of the states and one canrepresent the other. Hence, binary numbers are convenient to use in analysingor designing digital circuits.

2.5 DECIMAL NUMBER SYSTEM

The number system which utilizes ten distinct digits, i.e., 0, 1, 2, 3, 4, 5, 6, 7, 8 and9 is known as decimal number system. It represents numbers in terms of groups often, as shown in Figure 2.2.

Page 6: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

150 Self-Instructional Material

Number System andProgramming Languages

NOTES

We would be forced to stop at 9 or to invent more symbols if it were notfor the use of positional notation. It is necessary to learn only 10 basic numbersand positional notational system in order to count any desired figure.

Figure 2.2 Decimal Position Values as Powers of 10

The decimal number system has a base or radix of 10. Each of the tendecimal digits zero through nine, has a place value or weight depending on itsposition. The weights are units, tens, hundreds and so on. The same can be writtenas the power of its base as 100, 101, 102, 103... etc. Thus, the number 1993represents quantity equal to 1000 + 900 + 90 + 3. Actually, this should be writtenas {1 × 103 + 9 × 102 + 9 × 101 + 3 × 100}. Hence, 1993 is the sum of all digitsmultiplied by their weights. Each position has a value 10 times greater than theposition to its right.

For example, the number 379 actually stands for the followingrepresentation.

100 10 1102 101 100

3 7 93 × 100 + 7 × 10 + 9 × 1

∴ 37910 = 3 × 100 + 7 × 10 + 9 × 1= 3 × 102 + 7 × 101 + 9 × 100

In this example, 9 is the least significant digit (LSD) and 3 is the most significantdigit (MSD).Example 1. Write the number 1936.469 using decimal representation.

Solution: 1936.46910 = 1 × 103 + 9 × 102 + 3 × 101 + 6 × 100 + 4 × 10–1

+ 6 × 10–2 + 9 × 10–3

= 1000 + 900 + 30 + 6 + 0.4 + 0.06 + 0.009 = 1936.469

It is seen that powers are numbered to the left of the decimal point starting with 0and to the right of the decimal point starting with –1.

The general rule for representing numbers in the decimal system by usingpositional notation is as follows:

anan – 1 ... a2a1a0 = an10n + an – 110n–1 + ... a2102 + a1101 + a0100

Where n is the number of digits to the left of the decimal point.

Page 7: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

Number System andProgramming Languages

NOTES

Self-Instructional Material 151

2.6 OCTAL NUMBER SYSTEM

The octal number system was used extensively by early minicomputers. However,for both large and small systems, it has largely been supplanted by the hexadecimalsystem. Sets of 3 bit binary numbers can be represented by octal numbers and thiscan conveniently be used for the entire data in the computer.

A number system that uses eight digits, 0, 1, 2, 3, 4, 5, 6 and 7 is called anoctal number system.

It has a base of eight. The digits, 0 through 7 have exactly the same physicalmeaning as decimal symbols. In this system, each digit has a weight correspondingto its position as shown below:

an8n + ... a383 + a282 + a181 + a– 18–1 + a– 28–2 + ... + a– n8–n

Octal Odometer

Octal odometer is a hypothetical device similar to the odometer of a car. Eachdisplay wheel of this odometer contains only eight digits (teeth), numbered 0 to 7.When a wheel turns from 7 back to 0 after one rotation, it sends a carry to the nexthigher wheel. Table 2.1 shows equivalent numbers in decimal, binary and octalsystems.

Table 2.1 Equivalent Numbers in Decimal, Binary and Octal Systems

Decimal (Radix 10) Binary (Radix 2) Octal (Radix 8)

0 000 000 0

1 000 001 12 000 010 23 000 011 34 000 100 45 000 101 56 000 110 67 000 111 78 001 000 109 001 001 11

10 001 010 1211 001 011 1312 001 100 1413 001 101 1514 001 110 1615 001 111 1716 010 000 20

Consider an octal number [567.3]8. It is pronounced as five, six, seven octal pointthree and not five hundred sixty seven point three. The co-efficients of the integerpart are a0 = 7, a1 = 6, a2 = 5 and the co-efficient of the fractional part is a– 1 = 3.

Page 8: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

152 Self-Instructional Material

Number System andProgramming Languages

NOTES

CHECK YOUR PROGRESS

1. Name the systems of arithmetic used in digital system.2. What is a nibble?3. What is an octal number system?

2.7 HEXADECIMAL NUMBER SYSTEM

The hexadecimal system groups numbers by sixteen and powers of sixteen.Hexadecimal numbers are used extensively in microprocessor work. Mostminicomputers and microcomputers have their memories organized into sets ofbytes, each consisting of eight binary digits. Each byte either is used as a singleentity to represent a single alphanumeric character or broken into two 4 bit pieces.When the bytes are handled in two 4 bit pieces, the programmer is given theoption of declaring each 4 bit character as a piece of a binary number or as twoBCD numbers.

The hexadecimal number is formed from a binary number by grouping bits ingroups of 4 bits each, starting at the binary point. This is a logical way of grouping,since computer words come in 8 bits, 16 bits, 32 bits and so on. In a group of 4bits, the decimal numbers 0 to 15 can be represented as shown in Table 2.1.

The hexadecimal number system has a base of 16. Thus, it has 16 distinctdigit symbols. It uses the digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9 plus the letters A, B,C, D, E and F as 16 digit symbols. The relationship among octal, hexadecimal,and binary is shown in Table 2.2. Each hexadecimal number represents a group offour binary digits.

Table 2.2 Equivalent numbers in Decimal, Binary, Octal and HexadecimalNumber Systems

Decimal Binary Octal Hexadecimal(Radix 10) (Radix 2) (Radix 8) (Radix 16)

0 0000 0 01 0001 1 12 0010 2 23 0011 3 34 0100 4 45 0101 5 56 0110 6 67 0111 7 78 1000 10 89 1001 11 9

10 1010 12 A11 1011 13 B12 1100 14 C

Cont. ...

Page 9: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

Number System andProgramming Languages

NOTES

Self-Instructional Material 153

13 1101 15 D14 1110 16 E15 1111 17 F16 0001 0000 20 1017 0001 0001 21 1118 0001 0010 22 1219 0001 0011 23 13

20 0001 0100 24 14

Counting in hexadecimal

When counting in hex, each digit can be incremented from 0 to F. Once it reachesF, the next count causes it to recycle to 0 and the next higher digit is incremented.This is illustrated in the following counting sequences: 0038, 0039, 003A, 003B,003C, 003D, 003E, 003F, 0040; 06B8, 06B9, 06BA, 06BB, 06BC, 06BD,06BE, 06BF, 06C0, 06C1.

2.8 CONVERSION FROM ONE NUMBER SYSTEMTO THE OTHER

2.8.1 Binary to Decimal ConversionA binary number can be converted into decimal number by multiplying the binary1 or 0 by the weight corresponding to its position and adding all the values.

Example 2. Convert the binary number 110111 to decimal number.

Solution: 1101112 = 1 × 25 + 1 × 24 + 0 × 23 + 1 × 22 + 1 × 21 + 1 × 20

= 1 × 32 + 1 × 16 + 0 × 8 + 1 × 4 + 1 × 2 + 1 × 1

= 32 + 16 + 0 + 4 + 2 + 1

= 5510

We can streamline binary to decimal conversion by the following procedure:Step 1. Write the binary, i.e., all its bits in a row.Step 2. Write 1, 2, 4, 8, 16, 32, ..., directly under the binary number working

from right to left.Step 3. Omit the decimal weight which lies under zero bits.Step 4. Add the remaining weights to obtain the decimal equivalent.The same method is used for binary fractional number.Example 3. Convert the binary number 11101.1011 into its decimal quivalent.

Page 10: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

154 Self-Instructional Material

Number System andProgramming Languages

NOTES

Solution:

Step 1: 1 1 1 0 1 . 1 0 1 1

Binary Point

Step 2: 16 8 4 2 1 . 0.5 0.25 0.125 0.0625

Step 3: 16 8 4 0 1 . 0.5 0 0.125 0.0625

Step 4: 16 + 8 + 4 + 1 + 0.5 + 0.125 + 0.0625 = [29.6875]10

Hence, [11101.1011]2 = [29.6875]10

Table 2.3 lists the binary numbers from 0000 to 10000. Table 2.4 lists powers of2 and their decimal equivalents and the number of K. The abbreviation K standsfor 210 = 1024. Therefore, 1K = 1024, 2K = 2048, 3K = 3072, 4K = 4096, andso on. Many personal computers have 64K memory, this means that computerscan store up to 65,536 bytes in the memory section.

Table 2.3 Binary Numbers Table 2.4 Powers of 2

Decimal Binary Powers of 2 Equivalent Abbreviation

0 0 20 1

1 01 21 22 10 22 4

3 11 23 84 100 24 165 101 25 32

6 110 26 647 111 27 128

8 1000 28 2569 1001 29 512

10 1010 210 1024 1K

11 1011 211 2048 2K12 1100 212 4096 4K

13 1101 213 8192 8K14 1110 214 16384 16K

15 1111 215 32768 32K16 10000 216 65536 64K

2.8.2 Decimal to Binary Conversion

There are several methods for converting a decimal number to a binary number.The first method is simply to subtract values of powers of 2 which can be subtractedfrom the decimal number until nothing remains. The value of the highest power of2 is subtracted first, then the second highest and so on.

Page 11: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

Number System andProgramming Languages

NOTES

Self-Instructional Material 155

Example 4. Convert the decimal integer 29 to the binary number system.

Solution: First the value of the highest power of 2 which can be subtracted from29 is found. This is 24 = 16.

Then, 29 – 16 = 13

The value of the highest power of 2 which can be subtracted from 13, is 23, then13 – 23 = 13 – 8 = 5. The value of the highest power of 2 which can be subtractedfrom 5, is 22. Then 5 – 22 = 5 – 4 = 1. The remainder after subtraction is 10 or 20.Therefore, the binary representation for 29 is given by,

2910 = 24 + 23 + 22 + 20 = 16 + 8 + 4 + 0 × 2 + 1

= 1 1 1 0 1

[29]10 = [11101]2

Similarly, [25.375]10 = 16 + 8 + 1 + 0.25 + 0.125

= 24 + 23 + 0 + 0 + 20 + 0 + 2–2 + 2–3

[25.375]10 = [11011.011]2

This is a laborious method for converting numbers. It is convenient for small numbersand can be performed mentally, but is less used for larger numbers.

2.8.3 Double-Dabble Method

A popular method known as double-dabble method, also known as divide-by-two method, is used to convert a large decimal number into its binary equivalent.In this method, the decimal number is repeatedly divided by 2, and the remainderafter each division is used to indicate the co-efficient of the binary number to beformed. Notice that the binary number derived is written from the bottom up.Example 5. Convert 19910 into its binary equivalent.Solution: 199 ÷ 2 = 99 + remainder 1 (LSB)

99 ÷ 2 = 49 + remainder 149 ÷ 2 = 24 + remainder 124 ÷ 2 = 12 + remainder 0 12 ÷ 2 = 6 + remainder 0

6 ÷ 2 = 3 + remainder 03 ÷ 2 = 1 + remainder 11 ÷ 2 = 0 + remainder 1 (MSB)

The binary representation of 199 is, therefore, 11000111. Checking the result wehave,

[11000111]2 = 1 × 27 + 1 × 26 + 0 × 25 + 0 × 24 + 0 × 23 + 1 × 22

+ 1 × 21 + 1 × 20

= 128 + 64 + 0 + 0 + 0 + 4 + 2 + 1

Page 12: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

156 Self-Instructional Material

Number System andProgramming Languages

NOTES

∴ [11000111]2 = [199]10

Notice that the first remainder is the LSB and last remainder is the MSB. Thismethod will not work for mixed numbers.

2.8.4 Decimal Fraction to BinaryThe conversion of decimal fraction to binary fractions may be accomplished byusing several techniques. Again, the most obvious method is to subtract the highestvalue of the negative power of 2, which may be subtracted from the decimalfraction. Then, the next highest value of the negative power of 2 is subtracted fromthe remainder of the first subtraction, and this process is continued until there is noremainder or to the desired precision.

Example 6. Convert decimal 0.875 to a binary number.Solution: 0.875 – 1 × 2–1 = 0.875 – 0.5 = 0.375

0.375 – 1 × 2–2 = 0.375 – 0.25 = 0.1250.125 – 1 × 2–3 = 0.125 – 0.125 = 0

∴ [0.875]10 = [0.111]2

A much simpler method of converting longer decimal fractions to binary consistsof repeatedly multiplying by 2 and recording any carriers in the integer position.

Example 7. Convert 0.694010 to a binary number.

Solution: 0.6940 × 2 = 1.3880 = 0.3880 with a carry of 10.3880 × 2 = 0.7760 = 0.7760 with a carry of 00.7760 × 2 = 1.5520 = 0.5520 with a carry of 10.5520 × 2 = 1.1040 = 0.1040 with a carry of 10.1040 × 2 = 0.2080 = 0.2080 with a carry of 00.2080 × 2 = 0.4160 = 0.4160 with a carry of 00.4160 × 2 = 0.8320 = 0.8320 with a carry of 00.8320 × 2 = 1.6640 = 0.6640 with a carry of 10.6640 × 2 = 1.3280 = 0.3280 with a carry of 1

We may stop here as the answer would be approximate.

∴ [0.6940]10 = [0.101100011]2

If more accuracy is needed, continue multiplying by 2 until you have as many digitsas necessary for your application.

Example 8. Convert 14.62510 to binary number.

Solution: First the integer part 14 is converted into binary and then, the fractionalpart 0.625 is converted into binary as shown below:

Page 13: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

Number System andProgramming Languages

NOTES

Self-Instructional Material 157

Integer part Fractional part

14 ÷ 2 = 7 + 0 0.625 × 2 = 1.250 with a carry of 17 ÷ 2 = 3 + 1 0.250 × 2 = 0.500 with a carry of 03 ÷ 2 = 1 + 1 0.500 × 2 = 1.000 with a carry of 11 ÷ 2 = 0 + 1

∴ The binary equivalent is [1110.101]2

2.8.5 Octal to Decimal ConversionAn octal number can be easily converted to its decimal equivalent by multiplyingeach octal digit by its positional weight.

Example 9. Convert (376)8 to decimal number.

Solution: The process is similar to binary to decimal conversion except that thebase here is 8.

[376]8 = 3 × 82 + 7 × 81 + 6 × 80

= 3 × 64 + 7 × 8 + 6 × 1 = 192 + 56 + 6 = [254]10The fractional part can be converted into decimal by multiplying it by the negativepowers of 8.

Example 10. Convert (0.4051)8 to decimal number.Solution: [0.4051]8 = 4 × 8–1 + 0 × 8–2 + 5 × 8–3 + 1 × 8–4

= 1 1 1 14 0 5 18 64 512 4096

× + × + × + ×

∴ [0.4051]8 = [0.5100098]10

Example 11. Convert (6327.458) to its decimal number.

Solution: [6327.45]8 = 6 × 83 + 3 × 82 + 2 × 81 + 7 × 80 + 4 × 8–1 + 5 × 8–2

= 3072 + 192 + 16 + 7 + 0.5 + 0.078125[6327.45]8 = [3287.578125]10

2.8.6 Decimal to Octal ConversionThe methods used for converting a decimal number to its octal equivalent are thesame as those used to convert from decimal to binary. To convert a decimal numberto octal, we progressively divide the decimal number by 8, writing down theremainders after each division. This process is continued until zero is obtained asthe quotient, the first remainder being the LSD.

The fractional part is multiplied by 8 to get a carry and a fraction. The newfraction obtained is again multiplied by 8 to get a new carry and a new fraction.This process is continued until the number of digits have sufficient accuracy.

Page 14: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

158 Self-Instructional Material

Number System andProgramming Languages

NOTES

Example 12. Convert [416.12]10 to octal number.

Solution: Integer part 416 ÷ 8 = 52 + remainder 0 (LSD)

52 ÷ 8 = 6 + remainder 4

6 ÷ 8 = 0 + remainder 6 (MSD)Fractional part 0.12 × 8 = 0.96 = 0.96 with a carry of 0

0.96 × 8 = 7.68 = 0.68 with a carry of 70.68 × 8 = 5.44 = 0.44 with a carry of 50.44 × 8 = 3.52 = 0.52 with a carry of 30.52 × 8 = 4.16 = 0.16 with a carry of 40.16 × 8 = 1.28 = 0.28 with a carry of 10.28 × 8 = 2.24 = 0.24 with a carry of 20.24 × 8 = 1.92 = 0.92 with a carry of 1

∴ [416.12]10 = [640.07534121]8

Example 13. Convert [3964.63]10 to octal number.

Solution: Integer part 3964 ÷ 8 = 495 with a remainder of 4 (LSD)495 ÷ 8 = 61 with a remainder of 7

61 ÷ 8 = 7 with a remainder of 57 ÷ 8 = 0 with a remainder of 7 (MSD)

∴ [3964]10 = [7574]8

Fractional part 0.63 × 8 = 5.04 = 0.04 with a carry of 50.04 × 8 = 0.32 = 0.32 with a carry of 00.32 × 8 = 2.56 = 0.56 with a carry of 2 0.56 × 8 = 4.48 = 0.48 with a carry of 40.48 × 8 = 3.84 = 0.84 with a carry of 3 [LSD]

∴ [3964.63]10 = [7574.50243]8

Note that the first carry is the MSD of the fraction. More accuracy can be obtainedby continuing the process to obtain octal digits.

2.8.7 Octal to Binary ConversionSince eight is the third power of two, we can convert each octal digit into its 3 bitbinary form and from binary to octal form. All 3 bit binary numbers are required torepresent the eight octal digits of the octal form. The octal number system is oftenused in digital systems, especially for input/output applications. Each octal digitthat is represented by 3 bits is shown in Table 2.5.

Page 15: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

Number System andProgramming Languages

NOTES

Self-Instructional Material 159

Table 2.5 Octal to Binary Conversion

Octal digit Binary equivalent

0 000

1 001

2 010

3 011

4 100

5 101

6 110

7 111

10 001 000

11 001 001

12 001 010

13 001 011

14 001 100

15 001 101

16 001 110

17 001 111

Example 14. Convert [675]8 to binary number.

Solution: Octal digit 6 7 5

↓ ↓ ↓

Binary 110 111 101

∴ [675]8= [110 111 101]2

Example 15. Convert [246.71]8 to binary number.

Solution: Octal digit 2 4 6 . 7 1

↓ ↓ ↓ ↓ ↓

Binary 010 100 110 111 001

∴ [246.71]8 = [010 100 110 . 111 001]2

2.8.8 Binary to Octal ConversionThe simplest procedure is to use the binary-triplet method. The binary digitsare grouped into groups of three on each side of the binary point with zeros addedon either side if needed to complete a group of three. Then, each group of 3 bits isconverted to its octal equivalent. Note that the highest digit in the octal system is 7.

Example 16. Convert [11001.101011]2 to octal number.

Solution: Binary 11001.101011

Page 16: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

160 Self-Instructional Material

Number System andProgramming Languages

NOTES

Divide into groups of 3 bits 011 001 . 101 011↓ ↓ ↓ ↓3 1 5 3

Note that a zero is added to the left-most group of the integer part. Thus, thedesired octal conversion is [31.53]8.

Example 17. Convert [11101.101101]2 to octal number.

Solution: Binary [11101.101101]2

Divide into groups of 3 bits 011 101 . 101 101↓ ↓ ↓ ↓3 5 5 5

∴ [11101.101101]2 = [35.55]8

2.8.9 Hexadecimal to Binary ConversionHexadecimal numbers can be converted into binary numbers by converting eachhexadecimal digit to 4 bit binary equivalent using the code given in Table 3.1. If thehexadecimal digit is 3, it should not be represented by 2 bits [11]2, but it should berepresented by 4 bits as [0011]2.

Example 18. Convert [EC2]16 to binary number.

Solution: Hexadecimal number E C 2↓ ↓ ↓

Binary Equivalent 1110 1100 0010∴ [EC2]16 = [1110 1100 0010]2

Example 19. Convert [2AB.81]16 to binary number.

Solution: Hexadecimal number

2 A B . 8 1↓ ↓ ↓ ↓ ↓

0010 1010 1011 1000 0001∴ [2AB.81]16 = [0010 1010 1011 . 1000 0001]2

2.8.10 Binary to Hexadecimal ConversionConversion from binary to hexadecimal is easily accomplished by partitioning thebinary number into groups of four binary digits, starting from the binary point tothe left and to the right. It may be necessary to add zero to the last group, if it doesnot end in exactly 4 bits. Each group of 4 bits binary must be represented by itshexadecimal equivalent.

Page 17: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

Number System andProgramming Languages

NOTES

Self-Instructional Material 161

Example 20. Convert [10011100110]2 to hexadecimal number.

Solution: Binary number [10011100110]2

Grouping the above binary number into 4-bits, we have

0100 1110 0110Hexadecimal equivalent ↓ ↓ ↓

4 E 6∴ [10011100110]2 = [4E6]16

Example 21. Convert [111101110111.111011]2 to hexadecimal number.

Solution: Binary number [111101110111.111011]2

By Grouping into 4 bits we have, 1111 0111 0111 . 1110 1100↓ ↓ ↓ . ↓ ↓

Hexadecimal equivalent F 7 7 . E C

∴ [111101110111.111011]2 = [F77.EC]16

The conversion between hexadecimal and binary is done in exactly the same manneras octal and binary, except that groups of 4 bits are used.

2.8.11 Hexadecimal to Decimal ConversionAs in octal, each hexadecimal number is multiplied by the powers of sixteen,which represents the weight according to its position and finally adding all thevalues.

Another way of converting a hexadecimal number into its decimal equivalent is tofirst convert the hexadecimal number to binary and then convert from binary todecimal.

Example 22. Convert [B6A]16 to decimal number.

Solution: Hexadecimal number [B6A]16

[B6A]16 = B × 162 + 6 × 161 + A × 160

= 11 × 256 + 6 × 16 + 10 × 1 = 2816 + 96 + 10 =[2922]10

Example 23. Convert [2AB.8]16 to decimal number.

Solution: Hexadecimal number

[2AB.8]16 = 2 × 162 + A × 161 + B × 160 + 8 × 16–1

= 2 × 256 + 10 × 16 + 11 × 1 + 8 × 0.0625

∴ [2AB.8]16 = [683.5]10

Example 24. Convert [A85]16 to decimal number.

Page 18: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

162 Self-Instructional Material

Number System andProgramming Languages

NOTES

Solution: Converting the given hexadecimal number into binary, we have

[A85]16 = A 8 51010 1000 0101

[1010 1000 0101]2 = 211 + 29 + 27 + 22 + 20 = 2048 + 512 + 128 + 4 + 1

∴ [A85]16 = [2693]10

Example 25. Convert [269]16 to decimal number.Solution: Hexadecimal number

[269]16 = 20010

60110

91001

[001001101001]2 = 29 + 26 + 25 + 23 + 20 = 512 + 64 + 32 + 8 + 1

∴ [269]16 = [617]10

or, [269]16 = 2 × 162 + 6 × 161 + 9 × 160 = 512 + 96 + 9 = [617]10Example 26. Convert [AF.2F]16 to decimal number.Solution: Hexadecimal number

[AF.2F]16 = A × 161 + F × 160 + 2 × 16–1 + F × 16–2

= 10 × 16 + 15 × 1 + 2 × 16–1 + 15 × 16–2

= 160 + 15 + 0.125 + 0.0586∴ [AF.2F]16 = [175.1836]10

2.8.12 Decimal to Hexadecimal ConversionOne way to convert from decimal to hexadecimal is the hex Dabble method.The conversion is done in a similar fashion, as in the case of binary and octal,taking the factor for division and multiplication as 16.

Any decimal integer number can be converted to hex successively dividingby sixteen until zero is obtained in the quotient. The remainders can then be writtenfrom bottom to top to obtain the hexadecimal results.

The fractional part of the decimal number is converted to hexadecimal numberby multiplying it by sixteen and writing down the carry and the fraction separately.This process is continued until the fraction is reduced to zero or the requirednumber of significant bits is obtained.Example 27. Convert [854]10 to hexadecimal number.Solution: 854 ÷ 16 = 53 + with a remainder of 6

53 ÷ 16 = 3 + with a remainder of 53 ÷ 16 = 0 + with a remainder of 3

∴ [854]10 = [356]16Example 28. Convert [106.0664]10 to hexadecimal numberSolution: Integer part

106 ÷ 16 = 6 + with a remainder of 106 ÷ 16 = 0 + with a remainder of 6

Page 19: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

Number System andProgramming Languages

NOTES

Self-Instructional Material 163

Fractional part0.0664 × 16 = 1.0624 = 0.0624 + with a carry of 10.0624 × 16 = 0.9984 = 0.9984 + with a carry of 00.9984 × 16 = 15.9744 = 0.9744 + with a carry of 150.9744 × 16 = 15.5904 = 0.5904 + with a carry of 15

Fractional part [0.0664]10 = [0.10FF]16Thus, the answer is [106.0664]10 = [6A.10FF]16Example 29. Convert [65, 535]10 to hexadecimal and binary equivalents.Solution: (a) Conversion of decimal to hexadecimal number

65,535 ÷ 16 = 4095 + with a remainder of F4095 ÷ 16 = 255 + with a remainder of F255 ÷ 16 = 15 + with a remainder of F15 ÷ 16 = 0 + with a remainder of F∴ [65535]10 = [FFFF]16

(b) Conversion of hexadecimal to binary numberF F F F

1111 1111 1111 1111∴ [65535]10 = [FFFF]16 = [1111 1111 1111 1111]2

A typical microcomputer can store up to 65,535 bytes. The decimaladdresses of these bytes are from 0 to 65,535. The equivalent binary addressesare from

0000 0000 0000 0000 to 1111 1111 1111 1111The first 8 bits are called the upper byte, and second 8 bits are called lower byte.When the decimal is greater than 255, we have to use both the upper byte and thelower byte.

2.8.13 Hexadecimal to Octal Conversion

This can be accomplished by first writing down the 4-bit binary equivalent ofhexadecimal digit and then partitioning it into groups of 3 bits each. Finally, the 3-bit octal equivalent is written down.Example 30. Convert [2AB.9]16 to octal number.Solution: Hexadecimal number 2 A B . 9

↓ ↓ ↓ ↓4 bit numbers 0010 1010 1011 . 10013 bit pattern 001 010 101 011 . 100 100

↓ ↓ ↓ ↓ ↓ ↓Octal number 1 2 5 3 . 4 4∴ [2AB.9]16 = [1253.44]8

Page 20: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

164 Self-Instructional Material

Number System andProgramming Languages

NOTES

Example 31. Convert [3FC.82]16 to octal number.Solution: Hexadecimal number 3 F C . 8 2

4 bit binary numbers 0011 1111 1100 . 1000 00103 bit pattern 001 111 111 100 . 100 000 100

↓ ↓ ↓ ↓ ↓ ↓ ↓Octal number 1 7 7 4 . 4 0 4

[3FC.82]16 = [1774.404]8Notice that zeros are added to the rightmost bit in the above two examples tomake them group of 3 bits.

2.8.14 Octal to Hexadecimal Conversion

It is the reverse of the above procedure. First the 3-bit equivalent of the octal digitis written down and partitioned into groups of 4 bits, then the hexadecimal equivalentof that group is written down.Example 32. Convert [16.2]8 to hexadecimal number.Solution: Octal number 1 6 . 2

↓ ↓ ↓3 bit binary 001 110 . 0104 bit pattern 1110 . 0100

↓ ↓Hexadecimal E . 4

∴ [16.2]8 = [E.4]16Example 33. Convert [764.352]8 to hexadecimal number.Solution: Octal number 7 6 4 . 3 5 2

3 bit binary 111 110 100 . 011 101 0104 bit pattern 0001 1111 0100 . 0111 0101 000

↓ ↓ ↓ ↓ ↓ ↓Hexadecimal number 1 F 4 . 7 5 0∴ [764.352]8 = [1F4.75]16

CHECK YOUR PROGRESS

4. What is a double-dabble method?5. How, is the binary Triplet method used?6. How can conversion from binary to hexadecimal be accomplished?

2.9 REPRESENTATION OF CHARACTERS

Binary data is not the only data handled by the computer. We also need to processalphanumeric data like alphabets (upper and lower case), digits (0 to 9) and specialcharacters like + – * / ( ) space or blank etc. These also must be internally representedas bits.

Page 21: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

Number System andProgramming Languages

NOTES

Self-Instructional Material 165

Binary Coded Decimal (BCD)Binary Coded Decimal (BCD) is one of the early memory codes. It is based on theconcept of converting each digit of a decimal number into its binary equivalent ratherthan converting the entire decimal value into a pure binary form. It further uses fourdigits to represent each of the digits. Table 2.6 shows the BCD equivalent of thedecimal digits.

Table 2.6 BCD Equivalent of Decimals

Decimal Number Binary Equivalent0 0000 1 0001 2 0010 3 0011 4 0100 5 0101 6 0110 7 0111 8 1000 9 1001

Converting (42)10 into its BCD equivalent, would result in:

(42)10 = 0100

40100

2 or 01000010 in BCD

As seen, 4 bit BCD code can be used to represent decimal numbers only.Since 4 bits are insufficient to represent the various other characters used by thecomputer, instead of using only 4-bits (giving 16 possible combinations), computerdesigners commonly use 6 bits to represent characters in BCD code. In this, the 4BCD numeric place positions are retained, but two additional zone positions areadded. With 6 bits it is possible to represent 26 or sixty-four different characters.This is therefore sufficient to represent the decimal digits (10), alphabetic characters(26), and special characters (28).

Extended Binary Coded Decimal Interchange (EBCDIC)The major drawback with the BCD code is that it allows only sixty-four differentcharacters to be represented. This is not sufficient to provide for decimal numbers(10), lowercase letters (26), uppercase letters (26), and a fairly large number ofspecial characters (28 plus).

The BCD code was therefore extended from a 6 bit to an 8 bit code. Theadded 2 bits are used as additional zone bits, expanding the zone bits to four. Thisresulting code is called the Extended Binary Coded Decimal Interchange Code(EBCDIC). Using the EBCDIC it is possible to represent 28 or 256 characters.This takes care of the character requirement along with a large quantity of printableand several non-printable control characters (movement of the cursor on the screen,vertical spacing on printer etc.).

Page 22: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

166 Self-Instructional Material

Number System andProgramming Languages

NOTES

Since EBCDIC is an 8 bit code, it can easily be divided into two 4 bitgroups. Each of these groups can be represented by one hexadecimal digit(explained earlier in this unit). Thus, hexadecimal number system is used as anotation for memory dump by computers that use EBCDIC for internalrepresentation of characters.

Developed by IBM, EBCDIC code is used in most IBM models and manyother computers.

American Standard Code for Information Interchange (ASCII)A computer code that is very widely used for data interchange is called the ‘AmericanStandard Code for Information Interchange’ or ASCII. Several computermanufacturers have adopted it as their computers’ internal code. This code usesseven digits to represent 128 characters. Now an advanced ASCII is used having8 bit character representation code allowing for 256 different characters. Thisrepresentation is being used in micro computers.

Let us look at the encoding method. Table 2.7 below shows the bit combinationsrequired for each character.

Table 2.7 Bit Combinations for Each Character

R

00

10

20

30

40

50

60

70

00

NUL

DLE

0

@

P

'

p

01

SOH

DC1

!

1

A

Q

a

q

02

STX

DC2

"

2

B

R

b

r

03

ETX

DC3

#

3

C

S

c

s

04

EOT

DC4

$

4

D

T

d

t

05

ENQ

NAK

%

5

E

U

e

u

06

ACK

SYN

&

6

F

V

f

v

07

BEL

ETB

7

G

W

g

w

08

BS

CAN

(

8

H

X

h

x

09

TAB

EM

)

9

I

Y

i

y

0A

LF

SUB

*

:

J

Z

j

z

0B

VT

ESC

+

;

K

[

k

{

0C

FF

FS

,

<

L

\

l

|

0D

CR

GS

-

=

M

]

m

}

0E

SO

RS

.

>

N

^

n

~

0F

SI

US

/

?

O

_

o

DEL

Thus, to code a text string ‘Hello.’ in ASCII using hexadecimal digits:

H e l l o .48 65 6C 6C 6F 2E

The string is represented by the byte sequence 48 65 6C 6C 6F 2E.

2.10 INTEGERS AND FRACTIONS

Binary Fractions

A binary fraction can be represented by a series of 1 and 0 to the right of a binarypoint. The weights of digit positions to the right of the binary point are given by2–1, 2–2, 2–3 and so on.

Page 23: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

Number System andProgramming Languages

NOTES

Self-Instructional Material 167

For example, the binary fraction 0.1011 can be written as,

0.1011 = 1 × 2–1 + 0 × 2–2 + 1 × 2–3 + 1 × 2–4

= 1 × 0.5 + 0 × 0.25 + 1 × 0.125 + 1 × 0.0625(0.1011)2 = (0.6875)10

Mixed NumbersMixed numbers contain both integer and fractional parts. The weights of mixednumbers are

23 22 21 . 2–1 2–2 2–3 etc.↑

Binary PointFor example, a mixed binary number 1011.101 can be written as,

(1011.101)2 = 1 × 23 + 0 × 22 + 1 × 21 + 1 × 20 + 1 × 2–1 + 0 × 2–2

+ 1 × 2–3

= 1 × 8 + 0 × 4 + 1 × 2 + 1 × 1 + 1 × 0.5 + 0 × 0.25+ 1 × 0.125

∴ [1011.101]2 = [11.625]10

When different number systems are used, it is customary to enclose the numberwithin big brackets and the subscripts indicate the type of the number system.

2.10.1 Floating Point Representation of Numbers

In decimal, very large and very small numbers are expressed in scientific notationsuch as 4.69 × 1023 and 1.601 × 10–19. Binary numbers can also be expressed inthis same notation by floating point representation. The floating point representationof a number consists of two parts. The first part represents a signed, fixed pointnumber called the mantissa. The second part designates the position of the decimal(or binary) point and is called the exponent. The fixed point mantissa may be afraction or an integer. The number of bits required to express the exponent andmantissa are determined by the accuracy desired from the computing system aswell as its capability to handle such numbers. The decimal number + 6132.789,for example, is represented in floating point as follows:

sign0 6132789

mantissa1 244 344

sign0 04exponent124 34

The mantissa has a 0 in the leftmost position to denote a plus. The mantissahere is considered to be a fixed point fraction. So, the decimal point is assumed tobe at the left of the MSB. The decimal mantissa, when stored in a register requiresat least 29 flip-flops–four flit flops for each BCD digit and one for the sign. Thedecimal part is not physically indicated in the register; it is only assumed to bethere. The exponent contains the decimal number + 04 (in BCD), to indicate thatthe actual position of the decimal point is four decimal positions to the right of the

Page 24: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

168 Self-Instructional Material

Number System andProgramming Languages

NOTES

assumed decimal point. This representation is equivalent to the number expressedas fraction times 10 to exponent, that is, + 0.6132789 × 10+04. Because of thisanalogy, the mantissa is sometimes called the fraction part.

Consider the following decimal numbers to understand floating point notation.

(a) 42300(b) 369.4202(c) 0.00385(d) 643.15

The above numbers can be written in floating point representation as follows:(a) 42300 = 423 × 102

(b) 369.4202 = 0.3694202 × 103

(c) 0.00385 = 385 × 10–5

(d) 643.15 = 64315 × 10–2

Here the first or the integer part is known as mantissa. The mantissa is multipliedby some power of 10 and this power is known as the exponent.

Consider, for example, a computer that assumes integer representation forthe mantissa and radix 8 for the numbers. The octal number + 36.754 = 36754 ×8–3, in its floating point representation will look like this:

mantissa

sign0 36754

exponent

sign1 03

When this number is represented in a register, in its binary-coded form,the actual value of the register becomes

0011 110 111 101 100 1 000 011The register needs 23 flip-flops. The circuits that operate on such data must

recognize the flip-flops assigned to the bits of the mantissa and exponent and theirassociated signs. Note that if the exponent is increased by one (to –2) the actualpoint of the mantissa is shifted to the right by 3 bits (one octal digit).

Floating point is always interpreted to represent a number in the followingform:

m ×re

Only the mantissa m and the exponent e are physically represented in theregister. The radix r and the radix point position of the mantissa are always assumed.A floating point binary number is represented in a similar manner except that theradix assumed is 2. The number + 1001.11, for example, is represented in a 16 bitregister as follows:

sign0 100111000

mantissa1 2444 3444

sign0 00100

exponent1 244 344

Page 25: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

Number System andProgramming Languages

NOTES

Self-Instructional Material 169

The mantissa occupies 10 bits and the exponent 6 bits. The mantissa isassumed to be a fixed point representation. If the mantissa is assumed to be aninteger, the exponent will be 1 00101 (–5).

A floating point number is said to be normalized if the most significant positionof the mantissa contains a non-zero digit. The mantissa 035, for example, is notnormalized but 350 is. When 350 is represented in BCD, it becomes 0011 01010000 and although two 0s seem to be present in the two most significant positions,the mantissa is normalized. Since the bits represent a decimal number, not a binarynumber, and decimal numbers in BCD must be taken in groups of 4 bits, the firstdigit is 3 and is non-zero.

When the mantissa is normalized, it has no leading zeros and therefore containsthe maximum possible number of significant digits. Consider, for example, a registerthat can accommodate a mantissa of five decimal digits and a sign.

The number + 0.35748 × 102 = 35.748 is normalized because the mantissahas a non-zero digit 3 in its most significant position. This number can be representedin an unnormalized form as + 0.00357 × 104 = 35.7. This unnormalized numbercontains two most significant zeros and therefore the mantissa can accommodateonly three significant digits. The two least significant digits, 4 and 8, that wereaccommodated in the normalized form, have no form n the unnormalized formbecause the rgister can only accommodate five digits.

Arithmetic operations with floating point numbers are more complicated thanarithmetic operations with fixed point numbers and their execution takes longerand requires more complex hardware. However, floating point representation is amust for scientific computations because of the scaling problems involved withfixed point computations. Many computers and all electronic calculators havebuilt-in capability of performing floating point arithmetic operations. Computersthat do not have hardware for floating point computations have a set of subroutinesto help the user program his scientific problems with floating point numbers.

Exmaple 34. Determine the number of bits required to represent in floating pointnotation the exponent for decimal numbers in the range of 10+86.

Solution: Let n be the required number of bits to represent the number 10+86.

∴ 2n = 1086

n log 2 = 86

∴ n = 86/log 2 = 860 3010.

= 285.7

∴ 10±86 = 2±285.7.

The exponent ± 285 can be represented by a 10 bit binary word. It has a range ofexponent (+ 511 to – 512).

Page 26: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

170 Self-Instructional Material

Number System andProgramming Languages

NOTES

CHECK YOUR PROGRESS

7. Convert [2AB.9]16 to octal number.8. What concept is BCD based on?9. What is the major drawback with the BCD code?

2.11 BINARY ARITHMETIC

Arithmetic operations are done in computer not by using decimal numbers, as wedo normally, but by using binary numbers. Arithmetic circuits in computers andcalculators perform arithmetic and logic operations. All arithmetic operations takeplace in the arithmetic unit of a computer. The electronic circuit is capable of doingaddition of two or three binary digits at a time and the binary addition alone issufficient to do subtraction. Thus, a single circuit of a binary adder with suitableshift register can perform all the arithmetic operations.

2.11.1 Binary Addition

Binary addition is performed in the same manner as decimal addition. Binary additionis the key to binary subtraction, multiplication and division. There are only four casesthat occur in adding the two binary digits in any position. This is shown in Table 1.6.(a) 1 + 1 + 1 = 11 (i.e., 1 carry of 1 into next position)(b) 1 + 1 + 1 + 1 = 100(c) 10 + 1 = 11

The rules of (1), (2) and (3) in Table 2.8 are just decimal addition. The rule (4)states that adding 1 and 1 gives one zero (meaning decimal 2 and not decimal 10).There is a carry from the previous position. ‘Carry overs’ are performed in thesame manner as in decimal arithmetic. Since 1 is the larger digit in the binarysystem, any sum greater than 1 requires that a digit be carried out.

Table 2.8 Binary Addition

Sl. No. Augend Addend Carry Sum Result(A) + (B) (C) (S)

1 0 + 0 0 0 02 0 + 1 0 1 13 1 + 0 0 1 14 1 + 1 1 0 10

Example 35. Add the binary numbers (i) 011 and 101, (ii) 1011 and 1110, (iii)10.001 and 11.110, (iv) 1111 and 10010, and (v) 11.01 and 101.0111.

Page 27: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

Number System andProgramming Languages

NOTES

Self-Instructional Material 171

Solution: (i) Binary number Equivalent decimal number

11 ← Carry011 3

+ 101 5Sum = 1000 8

(ii) Binary Decimal (iii) Binary Decimal 11 ← Carry 1 ← Carry 1011 11 10.001 2.125+ 1110 + 14 + 11.110 + 3.750

Sum = 11001 25 Sum = 101.111 5.875

(iv) Binary Decimal (v) Binary Decimal 11 ← Carry 11 ← Carry 1111 15 11.01 3.25+ 10010 + 18 101.0111 + 5.4375

Sum = 100001 33 Sum = 1000.1011 8.6875

Since the circuit in all digital systems actually performs addition that can handleonly two numbers at a time, it is not necessary to consider the addition of morethan two binary numbers. When more than two numbers are to be added, the firsttwo are added together and then their sum is added to the third number and so on.Almost all modern digital machines can perform addition operation in less than1 μs.

Larger Binary NumbersColumn by column addition applies to binary as well as decimal numbers.Example 36. Add the following binary numbers.

(i) 1101101 and 1001110 (ii) 1111001 and 1100101

(iii) 110011 and 111000 (iv) 1111110 and 11100111

Solution: 1 1 1 carry 1 1 1 carry

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

(i) 1 0 0 1 1 1 0 (ii) 1 1 0 0 1 0 1

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

1 carry 1 1 1 1 1 1 carry

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

(iii) 1 1 1 0 0 0 (iv) 1 1 1 0 0 1 1 1

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

Page 28: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

172 Self-Instructional Material

Number System andProgramming Languages

NOTES

Example 37. Add these 8-bit numbers : 0110 1011 and 1011 0110. Then, showthe same numbers in hexadecimal notation.Solution: 8 bit binary Hexadecimal equivalent

1111 11 carry0110 1011 6 B H

+ 1011 0110 + B 6 H

10010 0001 1 2 1 H

Logic equations representing the sum is also known as the exclusive OR functionand can be represented also in Boolean ring algebra as S = AB BA+ = A ⊕ B.

2.11.2 Binary Subtraction

Subtraction is the inverse operation of addition. To subtract, it is necessary to establishprocedure for subtracting a large digit from a small digit. The only case in which thisoccurs with binary numbers is when 1 is subtracted from 0. The remainder is 1, butit is necessary to borrow 1 from the next column to the left. The rules of binarysubtraction are shown below in Table 2.9.1. 0 – 0 = 02. 1 – 0 = 13. 1 – 1 = 04. 0 – 1 = 0 with a borrow of 15. 10 – 1 = 01

Table 2.9 Binary Subtraction

Sl. No. Minuend _ Subtrahend ResultA B

1 0 – 0 0

2 0 – 1 0 with a borrow of 13 1 – 0 14 1 – 1 0

Example 38. (i) Binary Decimal (ii) Binary DecimalSolution: 1001 9 10000 16

– 101 – 5 – 011 –3

Difference = 100 4 1101 13

(iii) Binary Decimal (iv) Binary Decimal110.01 6.25 1101 13

– 100.1 – 4.5 – 1010 – 10

1.11 1.75 0011 3

Page 29: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

Number System andProgramming Languages

NOTES

Self-Instructional Material 173

Example 39. Show the binary subtraction of (128)10 from (210)10.

Solution: Converting the given decimal numbers into corresponding hexadecimalnumber, we have

210 → D 2 H → 1101 0010128 → 8 0 H → 1000 0000

1101 0010 D 2 H– 1000 0000 – 8 0 H

0101 0010 5 2 H

1’s and 2’s complimentsSubtraction of a number from another can be accomplished by adding thecomplement of the subtrahend to the minuend. The exact difference can be obtainedwith minor manipulations.

1’s Complement

The 1’s complement form of any binary number is obtained simply by changingeach 0 in the number to a 1 and each 1 in the number to a 0.

Binary number 1’s complement1011 → 0100110110 → 0010011100 1011 → 0011 0100

1011 1010 1011 1001 → 0100 0101 0100 0110

1’s complement arithmetic

(a) Subtrahend is smaller than the minuend.1. Complement the subtrahend by converting all 1’s to 0’s and all 0’s to 1’s.2. Proceed as in addition.3. Disregard the carry and add 1 to the total (end-around-carry).Example 40. Perform the subtractions using 1’s complement addition of thefollowing binary numbers:

(a) 110010 (b) 111001010 (c) 11010101– 101101 – 110110101 – 10101100

Solution: (a) 110010 ⇒ 110010 1s of101101

⎡ ⎤⎢ ⎥⎣ ⎦

'– 101101 + 010010

1000100 end-around-carry

1000101

Page 30: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

174 Self-Instructional Material

Number System andProgramming Languages

NOTES

(b) 111001010 ⇒111001010 1's of110110101

⎡ ⎤⎢ ⎥⎣ ⎦– 110110101 + 001001010

1000010100 end-around-carry1

00010101(c) 11010101 ⇒11010101 1's of

10101100⎡ ⎤⎢ ⎥⎣ ⎦– 10101100 + 01010011

100101000 end-around-carry 1

00101001

(b) Subtrahend is larger than the minuend.1. Complement the subtrahend.2. Proceed as in addition.3. Complement the result and place a negative sign in front of the result.

Example 41. Perform the subtractions using 1’s complement of the followingbinary numbers:

(a) 1011010 (b) 1101011 (c) 11110011– 1101010 – 1110101 – 11111010

Solution: (a) 1011010 ⇒ 1011010 1’s of1101010

⎛ ⎞⎜ ⎟⎝ ⎠– 1101010 + 0010101

11011111’s complement of 1101111 = – 0010000

(b) 1101011 ⇒ 1101011 1’s of1110101

⎛ ⎞⎜ ⎟⎝ ⎠– 1110101 + 0001010

11101011’s complement of 1110101 = – 0001010

(c) 11110011 ⇒ 11110011 1’s of11111010

⎛ ⎞⎜ ⎟⎝ ⎠– 11111010 + 00000101

111110001’s complement of 11111000 = – 00000111

Example 42. Use the 1’s complement to perform the following subtractions:(a) 1111–1011 (b) 110011–100101Solution: (a) Minuend 1111 1111

(b) Subtrahend – 1011 0100 (1’s of 1011)10011

10100

Page 31: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

Number System andProgramming Languages

NOTES

Self-Instructional Material 175

1111 – 1011 = 01002 = 410

(b) Minuend 110011 110011Subtrahend – 100101 + 011010 (1’s of 100101)

1001101 1

1110110011 – 100101 = 11102 = 1410

2’s Complement Subtraction(a) Subtrahend is smaller than the minuend1. Determine the 2’s complement of the smaller number.2. Add this to the larger number.3. Disregard the carry.

Example 43. Subtract the following using 2’s complement method: (i) (1011)2from (1100)2 (ii) (1001)2 10012 from 11012 (iii) 01012 from 10012.

Solution: (i) Direct subtraction 2’s complement method

1100 1100– 1011 + 0101 ← [2’s complement of 1011]

0001 Carry → 1 0001

∴ The carry is disregarded. Thus, the answer is (0001)2.

(ii) Direct subtraction 2’s complement method

1101 1101– 1011 0111 ← 2’s complement of 1001

0100 Carry → 1 0101

∴ The carry is disregarded. Thus, the answer is (0100)2.

(iii) Direct subtraction 2’s complement method

1001 1001

– 0101 + 1011 ← 2’s complement of 0101

0100 Carry → 1 0100

∴ The carry is disregarded. Thus, the answer is (0100)2.

(b) Subtrahend is larger than the minuend.

Page 32: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

176 Self-Instructional Material

Number System andProgramming Languages

NOTES

Example 44. Subtract the following using 2’s complement method : (i) (1011)2from (1101)2, (ii) (1100)2 from (1000)2.

Solution: (i) Direct subtraction 2’s complement method

1001 1001

– 1011 + 0101 ← 2’s complement of 1011

0010 No carry → 1110

No carry is obtained. Thus, the difference is negative and the true answer is 2’scomplement of (1110)2, i.e., (0010)2.

(ii) Direct subtraction 2’s complement method

1000 1000– 1100 + 0100 ← 2’s complement of 1100

0100 No carry → 1100

Since no carry is obtained, the difference is negative and therefore the true answeris the 2’s complement of (1100)2, i.e., (0100)2.

2.11.3 Binary Multiplication

The multiplication of binary numbers is done in the same manner as the multiplicationof decimal numbers. The following are four basic rules for multiplying binary digits:

(1) 0 × 0 = 0 (2) 0 × 1 = 0 (3) 1 × 0 = 0 (4) 1 × 1 =1In a computer, the multiplication operation is performed by repeated additions,

in much the same manner as the addition of all partial products to obtain the full product.Since the multiplier digits are either 0 or 1, so we are always multiplying by 0 or 1 andno other digit.Example 48. Multiply the binary numbers 1011 and 1101.

1011←Multiplicant = 1110

×1011 ← Multiplier = × 1310

14310

1011 0000 ← Partial product = 14310 1011 ← Final product = 14310 1011 10001111Example 49. Multiply the following binary numbers.

(i) 1 1 0 0× 1 0 1 0

0 0 0 01 1 0 0

0 0 0 0 1 1 0 01 1 1 1 0 0 0

12×10120

(ii) 1 0 1 1× 1 1 0 00 0 0 0

0 0 0 01 0 1 1

1 0 1 11 0 0 0 0 1 0 0

11×12132

Page 33: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

Number System andProgramming Languages

NOTES

Self-Instructional Material 177

(iii) 1 . 0 1×1 0 . 11 0 1

0 0 01 0 1 1 1 . 0 0 1

1.25×2.53.125

Typical 8 bit microprocessor 6502 is used in software multiplication. Inother words, multiplication is done with addition instructions.

2.11.4 Complement Arithmetic

Addition in the 2’s Complement System

There are four possible cases:(i) Both numbers positive

(ii) A positive number and a smaller negative number(iii) A negative number and a smaller positive number(iv) Both numbers negative

Figure 2.3 Binary Odometer Representation in 2’s Complement

The binary odometer is a marvellous way to understand 2’s complementrepresentation. There are two important ideas to notice about these odometerreadings: (i) The MSB is the sign bit : 0 for a + sign and 1 for a – sign (ii) Thenegative numbers shown in Figure 2.3 represents the 2’s complements of thepositive numbers.

Except for the magnitude, the positive and negative numbers are 2’scomplements of each other. Hence, we can take the 2’s complement of a positivebinary number to find the corresponding negative binary number.Case 1: Two positive numbersConsider the addition of + 29 and + 19.

+ 29 0001 1101 (augend)

Adding + 19 0001 0011 (addend)

+ 48 0011 0000 (sum = 48)

Case 2: Positive and smaller negative number

Consider the addition of +39 and –22, remembering that the –22 will be in its2’s complement form. Thus +22 (0001 0110) must be converted to –22 (11101010).

Page 34: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

178 Self-Instructional Material

Number System andProgramming Languages

NOTES

+ 39 0010 0111Adding – 22 1110 1010

17 1 0001 0001

This carry is disregarded, so the result is 10001.

In this case, the sign bit of addend is 1. The sign bits also participate in the processof addition. In fact a carry is generated in the last position of addition. This carry isalways disregarded.

Case 3: Positive and larger negative number

Consider the addition of –47 and +29.

– 47 1101 0001Adding + 29 0001 1101

– 18 1110 1110

The result has a sign bit of 1, indicating a negative number. It is in 2’s complementform. The last seven bits 110 1110, naturally represent the 2’s complement of thesum. To find the true magnitude of the sum, we must take the 2’s complement of1110 1110; the result is 10010 (+ 18). Thus, 1110 1110 represents – 18.

Case 4: Two negative numbers

Consider the addition of – 32 and – 44.

– 32 1110 0000 (augend)

Adding – 44 1101 0100 (addend)

– 76 11011 0100 (sum = – 76)

↑This carry is disregarded, so the result is 1011 0100.

Subtraction in 2’s Complement SystemAs in the case of addition, there are four cases. The subtraction operation usingthe 2’s complement system actually involves the operation of addition.

Case 1: Both positive numbers

Consider the case where 19 is to be subtracted from +28

+ 28 0001 1100+ 19 0001 0011

To subtract + 19 from + 28, the computer will send + 19 to a 2’s complementcircuit to produce – 19 1110 1101

The computer will then add + 28 and – 19 as follows:

Page 35: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

Number System andProgramming Languages

NOTES

Self-Instructional Material 179

+ 28 0001 1100Adding – 19 1110 1101

(Sum = 9) 1 0000 1001 disregard the carry

Case 2: Positive and smaller negative number

Consider that the minuend is + 39 and the subtrahend is – 21. In 2’s complementsystem, they appear as,

+ 39 0010 0111– 21 1110 1011

The computer sends – 21 to a 2’s complement circuit to produce,+ 21 0001 0101

The computer then adds + 39 and + 21 as follows:+ 39 0010 0111

Adding + 21 0001 0101

(Sum = 60) 0011 1100

Case 3: Positive and larger negative numberConsider that the minuend is + 19 and the subtrahend is – 43. In 2’s complementsystem, they appear as,

+ 19 → 0001 0011– 43 → 1101 0101

The computer sends the 2’s complement of – 43, i.e.,+ 43 → 0010 1011

Now the computer adds + 19 and + 43 as shown below:+ 19 → 0001 0011

Adding + 43 → 0010 1011

(sum = 62) 0011 1110

2.11.5 Signal Binary Number Representation

In digital computers, the binary numbers are represented by a set of binary storagedevices, such as flip-flops. Each device represents one bit. A 6 bit FF register, forexample, could store binary numbers ranging from 000000 to 111111 (0 to 63decimal). This represents the magnitude of the number. Since digital computers andcalculators handle positive as well as negative numbers, some means is required forrepresenting the sign of the number (+ or –). This is usually done by placing anotherbit called sign bit to the left of the magnitude bits. A 0 in the sign bit represents apositive number and a 1 in the sign bit represents a negative number. Therefore, –101, –100 and –010 are coded as 1101, 1100 and 1010 respectively.

The sign bit is used to indicate whether a stored number is positive or negative.The numbers in Figure 2.4 consists of a sign bit and seven magnitude bits. The

Page 36: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

180 Self-Instructional Material

Number System andProgramming Languages

NOTES

magnitude bits are true binary equivalent of the decimal value being represented.This is called the sign-magnitude system for representing signed binary numbers.

0 0 1 1 0 1 0 0 = + 5210

= – 3110

= +4610

Sign Magnitude

1 0 0 1 1 –1 1 1

1 0 1 0 1 1 1 0

Figure 2.4 Representation of Signed Numbers in Sign-magnitude Form

Three main signed number binary codes are used : (i) Sign magnitude (ii) 1’scomplement code, and (iii) 2’s complement code. The most commonly used systemfor representing signal binary numbers is the 2’s complement system.

CHECK YOUR PROGRESS

10. How are arithmetic operations done in a computer?11. Add the binary number, 1101101 and 1001110.12. Which is the most commonly used system for representing signal binary

numbers?

2.12 COMPUTER LANGUAGES AND ITS TYPES

A computer language is a language that can be understood by the computer. It isthe computer’s native language. Computer languages serve the same purpose ashuman languages. They are a means of communication. Let us understand thesimilarities and differences between computer languages and human languages.

A natural or human language is the language that people like us speakdaily, such as English, Hindi, French or German. It is made up of words and rulesknown as lexicon and syntax, respectively. These words are joined to makemeaningful phrases according to the rules of the syntax. A computer language alsoconsists of lexicon and syntax, i.e., characters, symbols and rules of usage thatallow the user to communicate with the computer.

The main difference between a natural language and computer language isthat natural languages have a large set of words (vocabulary) to choose from whilecomputer languages have a limited or restricted set of words. Thus, fewer wordsbut more rules characterize a computer language.

Each and every problem to be solved by the computer needs to be brokendown into discrete logical steps before the computer can execute it. The processof writing such instructions in a computer or programming language is calledprogramming or coding.

Page 37: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

Number System andProgramming Languages

NOTES

Self-Instructional Material 181

Just as computer hardware has improved over the years, programminglanguages have also moved from machine-oriented languages (that used strings ofbinary 0s and 1s) to problem-oriented languages (that use common English terms).All computer languages can, however, be classified under the following categories:

• Machine language (first-generation language)• Assembly language (second-generation language)• High-Level language (third-generation language)The characteristics of these are explained in the sections that follow.

Machine Language

The computer can understand only a binary-based language. This is a combinationof 0s and 1s. Instructions written using sequences of 0s and 1s are known asmachine language. First- generation computers used programs written in machinelanguage.

Machine language is very cumbersome to use and is tedious and timeconsuming for the programmer. It requires thousands of machine languageinstructions to perform even simple jobs like keeping track of a few addresses formailing lists.

Every instruction in machine language is composed of two parts – thecommand itself, also known as the ‘operation code’ or opcode (like add, multiply,move etc.), and the ‘operand’ which is the address of the data that has to be actedupon; for example, a typical machine language instruction may be represented asshown in Table 2.10.

Table 2.10 Representation of a Typical Machine Language

OP Code Operand

001 010001110

The number of operands varies with each computer and is therefore computerdependent.

It is evident from the above that to program in machine language, theprogrammer needs information about the internal structure of the computer. Hewill also need to remember a number of operation codes and will also need tokeep track of the addresses of all the data items (i.e., which storage location haswhich data item). Programming in machine language can be very tedious, timeconsuming and still highly prone to errors. Further, locating such errors and effectingmodifications is also a mammoth task. Quite understandably, programmers felt theneed for moving away from machine language.

Assembly Language

Assembly language was the first step in the evolution of programming languages. Itused mnemonics (symbolic codes) to represent operation codes and strings ofcharacters to represent addresses. Instructions in assembly language may look asshown in Table 2.11.

Page 38: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

182 Self-Instructional Material

Number System andProgramming Languages

NOTES

Table 2.11 Instructions in the Assembly Language

Operation Address

READ M

ADD L

Assembly language was designed to replace each machine code by anunderstandable mnemonic and each address with a simple alphanumeric string. Itwas matched to the processor structure of a particular computer and was therefore(once again) machine dependent. This meant that programs written for a particularcomputer model could not be executed on another one. In other words, an assemblylanguage program lacked portability.

A program written in assembly language needs to be translated into machinelanguage before the computer can execute it. This is done by a special programcalled ‘Assembler’ which takes every assembly language program and translatesit into its equivalent machine code. The assembly language program is known asthe source program, while the equivalent machine language program is known asthe object program. It may be useful to know that the assembler is a systemprogram supplied by the computer manufacturer. Second-generation computersused assembly language.

The lack of portability of programs (written using machine or assemblylanguages) between various computer systems led to the development of high-level languages. Since they allowed a programmer to overlook a lot of low-levelparticulars of the hardware of the computer system, they were called high-levellanguage programs. And it was obvious that if the syntax, mnemonics and rule andregulations of the programming language were closer to the natural language, itwould be easier for the programmer to program and the lesser the possibility ofintroducing errors (or bugs) into the program. Hence, third-generation languages,which were algorithmic and procedural, came into being in the mid-1950s. Theywere designed to solve a particular problem. They contained commands that areparticularly suited to one type of application. For example, a number of languageswere designed to process scientific or mathematical problems. Others emphasizedon commercial applications. These languages varied very little between differentcomputer systems, unlike machine or symbolic languages. But a complier or aninterpreter program was required to translate these machine codes. Once again,the high-level program is called the source code while its equivalent machinelanguage program is referred to as the object code.

Easy-to-learn feature, machine independence, easier maintenance andportability contributed to the popularity of high-level languages. Slow programexecution was the main disadvantage since programs needed to be converted intomachine language (by an interpreter or a compiler) before they could be executed.Some High-Level Languages

FORTRAN: FORTAN (FORmula TRANslation) was the first high -level languagedeveloped by John Backus at IBM in 1956.

Page 39: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

Number System andProgramming Languages

NOTES

Self-Instructional Material 183

FORTRAN has a number of versions with FORTRAN IV being one of theearlier popular versions. In 1977, the American National Standards Institute (ANSI)published standards for FORTRAN with a view to standardizing the form of thelanguage used by manufacturers. This standardized version is called FORTRAN 77.

COBOL: COBOL (COmmon Business Oriented Language), the firstlanguage used for commercial applications, was developed under the leadershipof Grace Hopper, a US Navy programmer, with a group of computer manufacturersand users in 1959. The maintenance and further growth of the language was handedover to a group called CODASYL (COnference on Data Systems Languages).

It is written using statements that resemble simple English and can beunderstood easily; for example, to add two numbers (stored in variables A and B),a simple statement in COBOL would be: ADD A TO B GIVING C.

COBOL was standardized by ANSI in 1968 and in 1974. COBOL becamethe most widely used programming language for business and data processingapplications.

BASIC: BASIC (Beginner's All-purpose Symbolic Instruction Code) wasdeveloped as a teaching tool for undergraduate students in 1966 by John Kemenyand Thomas Kurtz, two professors at Dartmouth College. Eventually BASIC wasused as the main language amongst the personal computer users.

A minimum version of BASIC was standardized by ANSI and is so simplethat it has been incorporated in every subsequent version of BASIC. Some versionsof BASIC include MBASIC (Microsoft BASIC), and CBASIC (Compiler basedBASIC).

One of the newer versions of BASIC, commonly known as Visual Basic,has also evolved from the original BASIC language. It contains various statementsand functions that can be used to create applications for a Windows or GUIenvironment.

PASCAL: PASCAL was designed by Nicholas Wirth, a Swiss professor,in 1971. It was developed as a more structured language used for teaching whichWirth named after the French mathematician Blaise Pascal, who also designed thefirst successful mechanical calculator. His primary aim was to provide a languagethat supported beginners learning good problem solving and programmingtechniques.

In addition to manipulation of numbers, PASCAL supports manipulation ofvectors, matrices, strings of characters, records, files and lists, thereby supportingnon-numeric programming. Hence, it has proved to be an attractive language forprofessional computer scientists.

PASCAL has been standardized by ISO (International StandardsOrganization) and ANSI.

PL/1 (Programming Language 1) was developed by IBM in the 1960s andwas the first language that was attempted to be used for a variety of applicationsrather than one particular area like business or science or artificial Intelligence.

Page 40: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

184 Self-Instructional Material

Number System andProgramming Languages

NOTES

LISP (LISt Processing) was developed in the early 1950s but wasimplemented in the 1959 by John McCarthy at the Massachusetts Institute ofTechnology. It became a standard language with the artificial intelligence communityand was a program that could easily handle recursive.

C language was developed by Dennis Ritchie of Bell Laboratories in orderto implement the operating system UNIX.

C ++ was developed by the Bjarne Stroustrup of Bell Laboratories byenhancing C. C++ is also used to write procedural programs like C but the reasonfor its increased popularity is perhaps because of its capability to handle the rigoursof object-oriented programming. C and C++ are the most extensively used general-purpose languages amongst programming experts.

JAVA: Java is again an object-oriented language like the C++ but is asimplified version with extra features. It is less prone to programming errors. Itwas developed for writing programs that could be safely and easily executedthrough the Internet. It is free from any kind of common virus threats. It is basicallya network-oriented language that can develop website pages with enhancedmultimedia features using small java programs known as java applets, Java is asecure to use over the Internet and is a platform independent language.

Fourth Generation Languages

Fourth generation languages are non-procedural. This means that they signify whatneeds to be accomplished but do not specify how to do it. Fourth-generationlanguages are characterized by simple English-like instructions and a quick andeasy learning process. They are so user-friendly that with little training and practicean individual can write his/her own programs and generate the desired reports. Itdoes not require the services of a professional programmer to do the same. Thefirst fourth-generation language, called FORTH, was developed by Charles Morre,an American astronomer, in 1970. FORTH is mainly used for industrial and scientificcontrol applications. FOCUS is another commonly known fourth-generationlanguage.Fifth Generation LanguagesFifth generation languages are an outgrowth of research in the area of artificialintelligence. They are, however, still in their infancy.

PROLOG (PROgramming LOGic): It is a logic programming language.It is a general purpose language often associated with artificial intelligence andcomputational linguistics. It has a purely logical subset, called pure Prolog, as wellas a number of extralogical features.

Prolog was developed in the early 1970s by two French computer scientists,Alain Colmerauer and Philippe Roussel.

Some of other popular languages include:GPSS (General Purpose System Simulator): Used for modelling physical

and environmental events

Page 41: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

Number System andProgramming Languages

NOTES

Self-Instructional Material 185

SNOBOL (String-Oriented Symbolic Language): Designed for patternmatching and list processing.

LOGO (a version of LISP): Developed in the 1960s to help children learnabout computers.

PILOT (Programmed Instruction Learning or Testing): Used in writinginstructional software.

2.13 GENERATION OF COMPUTER LANGUAGES

Language is a means of communication and a computer language is a means ofcommunication with computer. It is the means to pass instructions and data tocomputers. Thus, various computer languages are interfaces between a computerand a human being.

Computer does not understand alphabets or symbols used by human beings.It only recognizes presence or absence of a signal or changes in signal. Thus, onand off conditions are two discrete events that computer can understand.Symbolically, these are represented as 1 and 0, respectively. 0 stands for ‘off’condition and 1 represents ‘on’ condition. Thus, information understandable to acomputer is expressed as zeros and ones which is also called binary language. Butbinary language is incomprehensible for human understanding. So, first generationcomputer language used binary language comprising of 0s and 1s. This was knownas machine language.

Since, it was quite difficult to code programs in machine language and moredifficult to read the program written in 0s and 1s, computer scientists resorted tothe use of mnemonics, which used combinations of alphabets, special charactersand digits. This was second generation programming language and was calledassembly language programming. Since computer understands only machine codes,program written in assembly language has to be translated into machine language.This task is done by a special program called ‘Assembler’ which converts assemblylanguage program into its equivalent machine code. This was second generation ofcomputer language.

In third generation, came the concept of high level programming languages.Using these languages programmer created programs and used English-like wordsas commands. This became normal means of communication between user anddigital computer. These programs were to be translated to machine language forcomputer to understand and execute. This was done by another program, knownas ‘compiler’ that converted programs written in high level language into machinelanguage so that the computer can interpret and act on it.

After development of third generation, further development took place fordevelopment of fourth generation which was mostly in the form of query languageto retrieve data from a database and instructions were given as normal English-like sentences. Fifth generation used artificial intelligence that led to the development

Page 42: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

186 Self-Instructional Material

Number System andProgramming Languages

NOTES

of expert and knowledge based systems. The development of computer language,generation wise, is being given in Figure 2.5.

Figure 2.5 Development of Computer Language

First Generation LanguagesMachine language was the first generation computer language and all machines ofthat period used machine code consisting of 0s and 1s. Machine language codesare fast and highly efficient since they work directly on machine and allow totalcontrol of each operation. But writing programs in 0s and 1s was quite cumbersome,time consuming and prone to errors. Thus, following drawbacks were noted:

• Difficulty in writing program and debugging• Tedious programming process• Time consuming• Programs were error prone

Instruction written in machine language has two parts—the command(‘operation code’ or opcode such as add, multiply, move, etc.), and the ‘operand’which is the address of the data on which computer has to act upon. These codesare computer dependent and programmer needed information on internal structureof the computer and had to remember various operation codes and had to keeptrack of the addresses of all the data items. Period of machine language was 1940to mid 1950s. During this period program was fed to the computer by sitting onthe control panel, having toggle switches and input was given as 0s and 1s with thehelp of these toggle switches.

Second Generation Languages

Assembly language was second generation computer language. Developed in theearly 1950s, it used acronyms for coding and thus speeding up the programming.

Page 43: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

Number System andProgramming Languages

NOTES

Self-Instructional Material 187

This language performed operations such as add, sum, etc. This language too,was specific to machine and microprocessor and moving this program from onecomputer architecture to another, without writing the code for that computer, wasnot possible and this required learning another language to transfer the programs.Assembly language consists of characters of the alphabet, making programmingmuch easier than machine language and made use of mnemonics, or memory aids.This was, compared to machine language, much easier for the human programmerto recall.

A program written in assembly language has to be converted into machinelanguage for computer to execute it. A special program called ‘Assembler’ doesthis task. It takes assembly language program and translates it into its equivalentmachine code. But this language too, was machine dependent as programs wereto be written to match the processor structure of computer and programs writtenfor a particular computer model could not be executed on another one. In otherwords, an assembly language programs, like that of machine language, lackedportability.

Third Generation Language

In the period from 1956 to 1963 high level computer languages were developed.This period witnessed a major breakthrough in the history of computing. Adventof high level programming languages revolutionized the concept of programming.FORTRAN, COBOL, BASIC, Pascal, and C were such languages. High levellanguages are collectively known as 3GLs. But to make these programs readableby machine, a compiler is used. Programs written in high level language is calledsource program. Compiler converts source program into object code which ismachine readable.

FORTRAN

FORTRAN was developed in the period of 1956-57 by International BusinessMachine Corporation (IBM). The name FORTRAN is derived from two wordsFORmula TRANslater. This language was designed with a view to use it for scientificwork that involved complicated mathematical calculations. This language was thefirst high-level language used by many professional in the field of science andengineering.

ALGOL and COBOL

Subsequent to this, in the next few years, ALGOL was developed. ALGOL wasshortened form of two words ALGOrithmic Language which greatly influencedmany other languages and became the de facto way algorithms were described intextbooks and academic works for almost the next 30 years. Advent of COBOL(COmmon Business Oriented Language) is noteworthy. This changed the wayrecord keeping and data management was done in the businesses establishment.This is the first language that found widespread use in commercial applications.The program was developed in 1959 by Grace Hopper, a programmer in US

Page 44: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

188 Self-Instructional Material

Number System andProgramming Languages

NOTES

Navy. One great feature of this language was use of statements that resemblesimple English which is understood easily. For example, for adding two numbersstored in variables A and B, a simple statement is written as: ADD A TO B GIVINGC. In 1968, COBOL was standardized by ANSI and by 1974 COBOL becamethe most widely used programming language for business and data processingapplications. COBOL finds it root in a language called FLOWMATIC in 1955.This language had influence in the birth of COBOL-60 in 1959. Continuousimprovements were made in this language and subsequently COBOL 61, 65, 68,70 were developed. Latest version of COBOL 97 has included features like ObjectOriented Programming to keep pace up with current object oriented programminglanguages.

BASIC

BASIC (Beginner’s All-purpose Symbolic Instruction Code) was developed inthe early 1960s by scientists at Dartmouth College in New Hampshire. BASICwas designed for nonprofessional programmers and was the first computer languagefor this purpose. This became very popular during the period of 1970s and 1980s.This language with its variants got widespread use on microcomputers during thisperiod. One of the newer versions of BASIC, commonly known as Visual Basic,has also evolved from the original BASIC language. It contains various statementsand functions that can be used to create applications for a Windows or GUIenvironment. Microsoft Visual Basic with its net oriented version is known asVisual Basic.NET. As of 2006, 59% of developers for the .NET platform usedVisual Basic.NET as their only language.

PL/1 (Programming Language 1)It was developed in 1960s by IBM. It was the first language used for a variety ofapplications rather than one particular area like business or science or artificialIntelligence.

PASCAL and C

After 1960, many programming languages have been developed. PASCAL wasdeveloped as a tool for teaching and LISP for imparting computers some abilitieslike those associated with human intelligence. In this period, development of Clanguage was remarkable. In 1972, C was developed as a general purposeprogramming language by Brian Kernighan and Dennis Ritchie. This was developedfor UNIX operating system. Design of the language was originally aimed atimplementing system software. But its use is made for development of portableapplications. This has made C as the most popular programming languages forsystem programming as well as application programming. In present day scenariothere are few computer architectures for which a C compiler does not exist. C hasgreatly influenced many other popular programming languages, most notably isC++, which is an object oriented version and an extension to C.

Page 45: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

Number System andProgramming Languages

NOTES

Self-Instructional Material 189

C is an imperative (procedural) language for systems implementation andcan be compiled to provide low-level access to memory. It can provide languageconstructs for machine instructions with minimal run-time support. Thus, C is alsouseful for many applications, earlier coded in assembly language.

Although C has low-level capabilities it can be used for machine independentprogramming. Programs written in C can be compiled for a variety of computerplatforms and operating systems with little or no change to its source code. Theversatility of language is such that it works on many platforms, ranging fromembedded microcontrollers to supercomputers. C series of programs (i.e., C, C+, C#) made 3GL programs being used like store-bought software.

PERL (Practical Extraction and Report Language)

This is a high-level and general-purpose dynamic programming language. It iscompiled by interpreter. Originally, it was developed by Larry Wall who was alinguist, working as systems administrator for NASA, in 1987. He proposed it asa general-purpose UNIX scripting language with an objective to ease reportprocessing. Subsequent to that many changes and revisions were made and soonit became very popular amongst programmers. Perl has borrowed many featuresfrom other programming languages including C. The language has C like statements.

JAVA

In 1991, development was aimed at refinement in C++ to make it adaptable to theInternet. Sun Microsystems released Java in 1995. Java is an object-orientedprogramming language originally developed by James Gosling at Sun Microsystems.The syntax of this language was derived from C and C++ with simpler objectmodel and very few low-level facilities. There was one distinct feature of the objectoriented language which was compilation of Java application program. Javaapplications are compiled in bytecode and hence can be run on any machinehaving Java virtual machine (JVM). This is independent of computer architectureand hence, portable. Java formed the basis of the Netscape Internet browser.Using Java, files can be acquired from the Internet for running programs orsubprograms. Due to such adaptability, Java has become very popular as netoriented language.

Third generation languages were procedural in nature. Programmers, whoaim mostly at programming and computing, make use of third generation languagesand those who use the computers and programs for solving problems from otherapplications, use fourth generation languages.

Many 3GLs were block structured and this enabled development ofstructured programming which is based on the idea that a computer program canbe written using only three basic arrangements of the information such as sequential,selection, and iteration. In a sequential arrangement, execution is done one afterthe other, in a sequence. Here order is vital. The execution of the selection typestatement depends on execution of the first statement. More flexibility is there in

Page 46: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

190 Self-Instructional Material

Number System andProgramming Languages

NOTES

selection arrangement and choices are made with an IF...THEN...ELSE structure.The third type, iteration is also known as loop structure which specify on numberof times a loop will be executed. In a looping statement, command can be executeda number of times and will stop when the task is completed.

PASCAL and ALGOL are block-structured languages. BASIC,FORTRAN, and LISP are non-block structured languages. Block-structuredlanguages make modular construction. A module is a related set of commands andis block structured.

Fourth Generation LanguagesIn the period of 1970s-1990, the era of fourth generation programming language(abbreviated as 4GL) began. 4GLs were designed with an objective to developcommercial business software in a programming language. 4GL followed the eraof 3GL when programmers and developers aimed at designing systems towardhigher abstraction and more statement power and further development on 4GLsushered the era of 5GLs (Fifth Generation Languages).

Fourth generation languages are nonprocedural. A non procedural languagesignifies what is to be accomplished but do not specify a procedure. Such languageshave simple English-like instructions. These have a quick and easy learning process.They are user-friendly and not much of training is required. An ordinary user withvery little training and practice can write programs to generate desired reports.No expertise of a professional programmer is needed to do the same. FORTHwas the first fourth generation language, mainly used for industrial and scientificcontrol applications. It was developed in 1970, by Charles Morre, an Americanastronomer.

FOCUS is another commonly known fourth-generation language. FOCUSis a database query building language produced by Information Builders Inc. Itwas originally aimed at data handling and analysis on the IBM mainframe. Butsince newer systems were developed subsequently and smaller computers grewmore powerful, FOCUS could be used by personal computers. A web-basedversion of this program, known as ‘WebFOCUS’, was introduced and it couldrun the World Wide Web. Unlike general purpose programming languages, user/programmer may be less familiar with the technical details of the data and the wayit is stored. On the contrary user is required to be more familiar with the informationcontained in the data.

RAMIS was a languages with 4GL properties. This was portable. Cohendeveloped it at Mathematica (a mathematical software company). 4GL is moreadvanced than 3GLs which are also called traditional high level programminglanguages. Many 4GLs are in fact a mix of 3GL and 4GL. For example, the Listcommand of dBASE is a command of 4GL, but programmed applications indBASE, belong to 3GL. To differentiate between third and fourth-generation syntax,we take an example of a command that opens a customer file, displaying all namesand addresses on screen. Table 2.12 shows the diferences between third andfourth-generation syntax.

Page 47: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

Number System andProgramming Languages

NOTES

Self-Instructional Material 191

Table 2.12 Differences between third and fourth-generation syntax

dBASE 3GL dBASE 4GL

use customer use customerdo while .not. eof() list name, address? name, addressskip

enddo

Query language and report writers are 4GLs. A computer language havingEnglish-like commands and not requiring traditional input-process-output logic isput into this category. Functions of 4GLs are also built into graphical interfaces,which are activated by clicking and dragging. Commands are embedded into menusand buttons and selected in an appropriate sequence.

Fourth generation languages are more user friendly, portable and independentof operating systems. It should be used by non-programmers. This languageconstruct employs a database and dictionary management making applicationseasy and quick to change). This feature was not in COBOL or PL/I. Examples ofthis generation of languages are IBM’s APL, CSP and Power Builder, Access.APL (A Programming Language) is an array-oriented language which is interactiveand having integrated development environment. It finds use in scientific, actuarial,statistical, and financial applications. It is used for developing commercialapplications by programmers and by practitioners for their own work.

Communicating Sequential Processes (CSP) is a formal language usedto describe patterns of interaction in concurrent systems. It is based on mathematicaltheories of concurrency which is known as process algebras, or process calculi.PowerBuilder is a computer application development system created byPowersoft, now taken over by Sybase. It is marketed as a system for RapidApplication Development (RAD) and hence known as RAD system. It has toolsto create user interface and reports, and for accessing database content. ACCESSby Microsoft is a relational database available under the package MS Office.

Many fourth generation languages use query language to retrieve informationfrom the database. Structured Query Language (SQL) is a query language whichused for making queries from the database using commands that are English-likesentences. It was developed at IBM for developing information by retrieving datastored in relational databases. It was adopted by ANSI (American NationalStandards Institute) and subsequently, by ISO (International StandardsOrganization) as a method for managing structured and factual data. Thus,information systems, developed using 4GLs are independent of vendor, operatingsystem, and computer platform.

Caper Jones provided a quantitative definition of 4GL and suggested metricsto measure its quality. Capers Jones has defined programming languages of variousgenerations in terms of developer productivity. The measurement was given asfunction points (FP) per staff-month (SM). According to his definition, a 4GL

Page 48: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

192 Self-Instructional Material

Number System andProgramming Languages

NOTES

language supports 12–20 FP/SM which is equivalent to 16 to 27 lines of code inone function point.

4GLs are considered as subsets of domain-specific languages according tosome researchers. Domain-specific language (DSL) is a programming languagededicated to a particular problem domain. Given the persistence of assemblylanguage even now in advanced development environments (MS Studio), oneexpects that a system ought to be a mixture of all the generations, with only verylimited use of the first.

The term 4GL applies to a large set of software products. 3GL empoweredprogrammers but 4GL empowered non-programmers by enhancing developmentenvironment to them.

Thus, using 4GL is like a processing in ‘black box’ in which every newgeneration further away from the machine and closer to domain. As an applicationpackage a 4GL is business oriented or dealing with some technical domain.

Types of 4GLs

• Codeless programming: Such 4GLs make use of libraries with runtimeframework. These are also known as table driven programs. Developerdefines logic according to operation as a list of data table that manipulatescommands. Thus, in 4GLs table-driven algorithm programming is used.eDeveloper is an example of this type of 4GL. These are used for businessapplication development and come with GUI screens and report editors.

• Report generators: These packages use data format to generate directlydirectly or a program is generated for generating report.

• Forms generators: Such programs are meant for managing interactionsonline with users. Alternatively they resort to generation of programs toaccomplish it.

• System generators: Such a language automatically generates wholesystems from the outputs of CASE tools, specifications of screens andreports.Some 4GLs have integrated tools which allow for the easy specification of

all the

Fifth Generation Languages (5GLs)

This generation of languages resulted due to an outgrowth of research in the areaof artificial intelligence.

PROLOG (PROgramming LOGic): It is a language that doesprogramming in logic. It is a general purpose language in the field of artificialintelligence and computational linguistics. It contains a part, known as pure Prologwhich is a logical subset of the whole PROLOG. It also has a number of extralogicalfeatures.

Page 49: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

Number System andProgramming Languages

NOTES

Self-Instructional Material 193

It was developed in the early 1970s by two French computer scientists,Alain Colmerauer and Philippe Roussel.

Prolog is based on formal logic and is declarative. The logic of program isexpressed as relations. Execution of the program is done by running queries oversuch relations. Prolog uses term as single data type. Relations and queries areconstructed using term. Relations are defined as clauses. It works on the principleof resolution. If a query is given, Prolog engine searches for a resolution refutationof the negated query. This feature has made Prolog especially useful for applicationsin parsing of language and symbolic mathematics.

LISP

LISP is a family of programming languages having a long history. It has a fullyparenthesized syntax. It was first specified in 1958 and that way it is the secondoldest high level programming language after FORTRAN. LISP from that time(when it was taken as 3GL) has changed much and now it is language for applicationof artificial intelligence and hence it is a 5GL. A number of dialects of LISP haveexisted. Common Lisp and Scheme are two examples.

Originally, it was meant for handling mathematical notation in computerprograms and was based on lambda calculus. Capability to use mathematicalnotations made LISP more suitable for artificial intelligence (AI) research. Thename LISP has been derived from two words ‘List Processing’. Source code ofthis language consists of lists and linked lists are main data structures of this language.Due to this, programs written in LISP are capable of manipulating source code asa data structure. This can create macro systems enabling programmers for creatingnew syntax. This has also added capability to LISP in embedding new domain-specific programming languages in LISP.

LOGO: To teach computer principles to children this language wasdeveloped in the 1960s. It is considered a dialect of LISP. LOGO is for functionalprogramming. Unlike LISP, parentheses are not used in LOGO, hence, it is calleda LISP without the parentheses.

Some of other popular languages include:GPSS (General Purpose System Simulator): This language finds use is

modeling events, physical and environmental. Originally, its name was Gordon’sProgrammable Simulation System. Geoffrey Gordon was the creator of thisprogramming language. Changes in name was made before releasing launchingthis product.

SNOBOL (String-Oriented Symbolic Language): This was created for usein pattern matching and list processing. It was developed by David J. Farber,Ralph E. Griswold and Ivan P. Polonsky in the period of 1962 and 1967.

PILOT (Programmed Instruction Learning or Testing): This language wasfound very much suitable for writing instructional software. It was used for thetechnology of computer assisted instruction (CAI). It is a special programming

Page 50: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

194 Self-Instructional Material

Number System andProgramming Languages

NOTES

language which is very easy for beginners to learn. It is available for several brandsof microcomputers. PILOT contains fewer commands than most other languages.

Thus, 5GLs are mostly concerned with development of intelligent systems,working in the field of artificial intelligence. This is the area in the filed of computerscience that works for imparting intelligence to computers like that of human beings.John McCarthy at the Massachusetts Institute of Technology coined this term in1956. Artificial intelligence creates programs for:

• Games playing: Chess and Checkers.• Expert systems: Using knowledgebase for making decisions in real

life situations.• Natural language: For understanding natural human languages.• Neural networks: For simulating network of human brain.• Robotics: These are system design by programming computers to

empower a machine for seeing, hearing and reacting to different sensorystimuli, like a human being.

Neural network is a programming construct imparting intelligence tocomputers such that it can imitate the working of a human brain. It does not makeuse of a digital model that works on zeros and ones. It works by providingconnections between processing elements, which are computer equivalent ofneurons. Such approach is very effective in prediction of events when these networksform a huge database of many examples to draw on. Although a neural networkimplies a non-digital computer, these are simulated on digital computers.

Currently, no computer system designed so far exhibit full artificial intelligence.

CHECK YOUR PROGRESS

13. What language can a computer understand?14. True or False

(a) Fourth generation languages are non-procedural.(b) Computer understands alphabets or symbols used by human beings.

15. Which was the second generation computer language?16. What is Java?

2.14 CHARACTER CODES

A code is a symbol or group of symbols that stands for something. It is arepresentation of discrete elements of information, which may be in the form ofnumbers, letters or any other varying physical quantities. Binary bits 1 and 0 areoften used in groups. The codes are used to communicate the information to thedigital computer and to retrieve from it. The purpose of the code is that the operatorcan feed data into computers directly in decimal numbers, alphabets and special

Page 51: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

Number System andProgramming Languages

NOTES

Self-Instructional Material 195

characters. The computer in turn converts these data in binary code which it canprocess and after computation, it again converts the binary data into decimalnumbers, alphabets and special characters which we could understand easily.

Certain binary codes are used for arithmetic operations. Other codes facilitatethe creation of digital transducers for entering information into a system.

Binary Coded Decimal (BCD) Code

Several binary codes are used to express decimal numbers, alphabets, specialcharacters and for display. Digital systems, for their internal operations, use someform of binary numbers. However, the external world is decimal in nature. In manyapplications, special codes are used for such auxiliary functions as error detectionand correction.

Binary Coded Decimal or BCD uses binary number system to specify thedecimal numbers 0 to 9. It is composed of 4 bits. The weights are assignedaccording to the position occupied by these digits. The weight of the first (rightmost) position is 20 or 1, the second 21 or 2, the third 22 or 4 and the fourth 23 or8. Reading from left to right the weighting is 8 - 4 - 2 - 1 and the code is alsocalled the 8 - 4 - 2 - 1 code.

The numbers from 0 to 9 are represented as in binary but after 9, therepresentations are different. For example, the decimal number 12 in binary is[1100]2 but the same number in BCD is represented as [0001 0010]BCD. Therefore,the six code combinations 1010, 1011, 1100, 1110 and 1111 are invalid in BCDcode.Example 1: Write BCD for a decimal number 559.Solution: Decimal number → 5 5 9

↓ ↓ ↓BCD code → 0101 0101 1001

∴ [559]10 = [0101 0101 1001]BCD

Example 2: Write the decimal number 96.42 to its BCD code equivalent.Solution : Decimal number → 9 6 . 4 2

↓ ↓ ↓ ↓BCD code → 1001 0110 . 0100 0010

∴ [96.42]10 = [1001 0110 . 0100 0010]BCD

Excess-3 Code

The Excess-3 is a digital code that is derived by adding to each decimal digit andthen converting the result to four-bit binary. The Excess-3 code is used in somearithmetic circuits because it is self-complementing. Table 2.13 shows Excess-3codes to represent single decimal digit and its BCD code.

Page 52: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

196 Self-Instructional Material

Number System andProgramming Languages

NOTES

Table 2.13 BCD and Excess-3 Codes

DecimalBCD Excess-3 CodeDigit

0 0 0 0 0 0 0 1 11 0 0 0 1 0 1 0 02 0 0 1 0 0 1 0 13 0 0 1 1 0 1 1 04 0 1 0 0 0 1 1 15 0 1 0 1 1 0 0 06 0 1 1 0 1 0 0 17 0 1 1 1 1 0 1 08 1 0 0 0 1 0 1 19 1 0 0 1 1 1 0 0

Gray Code

The Gray code belongs to a class of codes called minimum change codes, inwhich only one bit in the code group changes when going from one step to thenext. Gray code is not an arithmetic code.

Table 2.14 Gray Code

DecimalBinary Code Gray CodeDigit

0 0 0 0 0 0 0 0 0 ←⎯⎯⎯⎯⎯⎯⎯

1 0 0 0 1 0 0 0 1 ⎯⎯⎯⎯⎯⎯⎯

2 0 0 1 0 0 0 1 1 ←⎯⎯⎯⎯⎯

3 0 0 1 1 0 0 1 0 ⎯⎯⎯⎯⎯

4 0 1 0 0 0 1 1 0 ←⎯⎯⎯

5 0 1 0 1 0 1 1 1 ←⎯⎯

6 0 1 1 0 0 1 0 1 ←⎯

7 0 1 1 1 0 1 0 0 ←

8 1 0 0 0 1 1 0 0 ←

9 1 0 0 1 1 1 0 1 ←⎯

10 1 0 1 0 1 1 1 1 ←⎯⎯

11 1 0 1 1 1 1 1 0 ←⎯⎯⎯

12 1 1 0 0 1 0 1 0 ←⎯⎯⎯⎯

13 1 1 0 1 1 0 1 1 ⎯⎯⎯⎯⎯⎯

14 1 1 1 0 1 0 0 1 ←⎯⎯⎯⎯⎯⎯

15 1 1 1 1 1 0 0 1 ←⎯⎯⎯⎯⎯⎯⎯

Table 2.14 shows the Gray code representation for the decimal numbers 0through 9 together with the straight binary code.

Page 53: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

Number System andProgramming Languages

NOTES

Self-Instructional Material 197

Alphanumeric Codes

Alphanumeric codes are the codes that represent alphabetic characters (letters),punctuation marks and other special characters. Alphanumeric code represents allof the various characters and functions that are found on a computer keyboard.

The ASCII Code

The abbreviation ASCII stands for the American Standard Code for InformationInterchange. The ASCII code is a 7-bit code used in transferring coded informationfrom keyboards and to computer displays and printers. It is used to representnumbers, letters, punctuation marks as well as control characters. For example,the letter A is represented by 100 0001.

EBCDIC Code

The abbreviation EBCDIC stands for the Extended Binary Coded DecimalInterchange Code. It is an 8-bit code in which the decimal digits are representedby the 8421 BCD code preceded by 1111.

Error-Detecting Codes

A code that uses n-bit strings need not contain 2n valid code words. An error-detecting code has the property that corrupting or garbling a code word will likelyproduce a bit string that is not a code word (a non-code word).

A system that uses an error-detecting code generates, transmits, and storesonly code words. Thus, errors in a bit string can be detected by a simple rule—ifthe bit string is a code word, it is assumed to be correct; if it is a non-code word,it contains an error.

ParityThe most simple and commonly used error detecting method is the parity checkmethod, in which an extra bit called parity bit is included with the binary message,to make the total number of 1s either odd or even, resulting in two methods; (i)Even-parity method and (ii) Odd-parity method.The ability of a code to detect single errors can be stated in terms of the conceptof distance. A code detects all single errors if the minimum distance between allpossible pairs of code words is 2.In general, (n + 1) bits are needed to construct a single-error detecting code with2n code words. The first n bits of a code word, called information bits, may beany of the 2n n-bit strings minimum error bit.

A code in which the total number of 1s in a valid (n + 1) bit code word is even; thisis called an even-parity code.

A code in which the total number of 1s in a valid (n + 1) bit code word is odd andthis code is called an odd-parity code. These codes are also sometimes called 1-bit parity codes, since they each use a single parity bit. The parity bit can be

Page 54: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

198 Self-Instructional Material

Number System andProgramming Languages

NOTES

placed at either end of the code word, such that the receiver must be able tounderstand the parity bit and the actual data.

An n-bit code and its error-detecting properties under the independent error modelare easily explained in terms of an n-cube. A code is simply a subset of the verticesof the n-cube. In order for the code to detect all single errors, no code-wordvertex can be immediately adjacent to another code-word vertex.

Figure 2.6(a) shows a 3-bit code with five code words. Code word 111 isimmediately adjacent to code words 110, 011 and 101. Since a single failurecould change 111 to 110, 011 or 101 bits code does not detect all single errors. Ifwe make 111 a non-code word, we obtain a code that does have the single-error-detecting property, as shown in Figure 2.6. No single error can change one codeword into another.

110 111

101

001000

100

010011

010

000

100

011

101

110 111

code wordnon-code word

001

(a) Minimum distance = 1 (b) Minimum distance = 2does not detect all single errors detects all single errors

Figure 2.6 Code Words in Two-different 3-Bit Codes

Table 2.15 Distance-2 Codes with Three Information Bits

Information Even-parity Odd-parityBits Code CodeXYZ XYZ P XYZ P

000 000 1 000 1

001 001 1 001 0

010 010 1 010 0

011 011 0 011 1

100 100 1 100 0

101 101 0 101 1

110 110 0 110 1

111 111 1 111 0

The 1-bit parity codes do not detect 2-bit errors, since changing two bits does notaffect the parity. However, the codes can detect errors in any odd number of bits.Actually, 1-bit parity codes error-detection capability stops after 1-bit errors.Other codes, with minimum distance greater than 2, can be used to detect multipleerrors. Table 2.15 shows the distance-2 codes with three information bits.

Page 55: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

Number System andProgramming Languages

NOTES

Self-Instructional Material 199

Checksum

Since the double error will not change the parity of the bits, the parity checker willnot indicate any error. The check sum method is used to detect double errors andpinpoint erroneous bits. The working of checksum method is explained as follows:

Initially word A 10110111 is transmitted. Next word B 00100010 istransmitted. The binary digits in the two words are added and the sum obtained isretained in the transmitter. Then, a word C is transmitted and added to the previoussum and the new sum is retained. Thus, each word is added to the previous sumand after the transmission of all the words, the final sum, called checksum is alsotransmitted. The same operation is also done independently at the receiver and thefinal sum obtained at the receiver is checked against the transmitted checksum. Ifthe two sums are equal, then there is no error.

ISCII Codes

Indian Script Code for Information Interchange (ISCII) consists of syllables. Fontsin ISCII are defined in glyphs for Indian languages. Element of writing is calledglyph. The document in ISCII is represented and edited in ISCII itself becauseonly ISCII text is recognized by supporting language tools and spell checkers. Nokeyboard is available to produce directly ISCII text; therefore keyboard mapperis required to generate the ISCII text from the normal keyboard. The two types ofkeyboards Inscript and Phonetic help in the task to produce ISCII text. It wasproposed in the eighties and evolved by 1991. ISCII syllables are produced byusing the keyboard mappers. The glyphs are produced from the ISCII text. Thenthe ISCII text is stored in the document for further processing. Conversion routinesand ISCII-glyph conversion tables are required for this. The length of text is notedby selecting with mouse and by justifying paragraph. When users select glyphs onthe screen, the corresponding ISCII text is cut/copied/pasted instead of the glyphs.The Indian language editors such as Baraha, UnitEdit etc. work directly onglyphs except iLeap. The main advantage of ISCII code table is that a super setof all characters is required in ten Brahmi-based Indian scripts. The 8-bit ISCIIcode retains the standard ASCII code which makes feasible to use Indian scriptswith existing English computers and software for 8-bit character codes. The Indianscript keyboard overlay is designed for the standard English QWERTY whichsupports 8-bit ISCII code standard. This is coexisted with the standard Englishcode which contains only the basic alphabets in order as contained in Indiandictionaries. The philosophy behind ISCII code is that it makes possible by theircommon origin from the Brahmi script. It also makes possible to the phoneticnature of the alphabet.

Figure 2.7 shows the Indian language editor, ‘UnitEdit’.

Page 56: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

200 Self-Instructional Material

Number System andProgramming Languages

NOTES

Figure 2.7 Indian Language Editor‘UnitEdit’

Features of ISCII

The features of ISCII representation are as follows:• It is a single representation of all Indian scripts.• Codes have been assigned in the upper region (range 160–255) for the

aksharas of the language.• It assigns code for the Matras means vowel extensions.• Special characters are included to specify consonants as syllables and scripts

in specific sections of text.• It represents syllables of Indian languages which vary from one byte to ten

bytes for syllables.• Consonants do not follow a sorting order of the aksharas across the

languages. Some aksharas of Tamil, Malayalam and Telugu are out ofplace in the assignment of codes.

• It uses a concept of Nukta character to indicate the required akshara.• It forms conjuncts as the halanth characters in which half form of the

consonant is present. Conjunct is a combination of two or more basic letters.It also provides the concept of the soft halanth as invisible consonants tohandle representations of special characters.

• It makes up parsing a text string which is language dependent.• It provides language independent code assignments but not accepts error

free and clean transliteration across languages. For example transliteratingTamil from Devanagari.

Page 57: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

Number System andProgramming Languages

NOTES

Self-Instructional Material 201

• It provides a standard of 600-800 basic syllables which provides arbitrarysyllables combining with all the vowels. If new words are introduced in thelanguage, it handles easily. Figure 2.8 shows the ISCII codes while Figure 2.9shows the ISCII character-set coded representation.

Figure 2.8 ISCII Codes

Figure 2.9 ISCII Character-set coded representation

Page 58: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

202 Self-Instructional Material

Number System andProgramming Languages

NOTES

Script dependent ISCII

The specific versions of ISCII for the different scripts are as follows:Devanagari ISCII, Gurmukhi ISCII, Gujarati ISCII, Oriya ISCII, Bengali

ISCII, Assamese ISCII, Telugu ISCII, Kannada ISCII, Malayalam ISCII, TamilISCII.

Devanagri ISCII

Figure 2.10 Codes used in Devanagri Script

Figure 2.10 shows the codes which are used in Devanagri script for theHindi language and other languages.

Gurmukhi ISCII

Figure 2.11 Gurmukhi ISCII Script used for Punjabi.

Figure 2.11 shows the Gurmukhi ISCII script used for Punjabi.

Gujarati ISCII

Figure 2.12 Gujarati ISCII

Figure 2.12 shows the Gujarati ISCII.

Page 59: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

Number System andProgramming Languages

NOTES

Self-Instructional Material 203

Oriya ISCII

Figure 2.13 Script in Oriya Language

Figure 2.13 shows the script used in Oriya language.

Bengali ISCII

Figure 2.14 Bengali Script

Figure 2.14 shows the Bengali script used in Bengali language.

Assamese ISCII

Figure 2.15 Assamese Script

Figure 2.15 shows the Assamese script is similar to Bengali script. But itsone glyph is different. The Assamese glyphs got their own distinctive code pointswhen the above two scripts are merged into a single code page.

Page 60: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

204 Self-Instructional Material

Number System andProgramming Languages

NOTES

Figure 2.16 ISCII Representation

Figure 2.16 shows the ISCII representation.

PC_ISCII

Figure 2.17 PC_ISCII

Page 61: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

Number System andProgramming Languages

NOTES

Self-Instructional Material 205

PC_ISCII (Figure 2.17) is an addition of ISCII code. This code is similarto the earlier code but its positions are completely different. The middle row in theabove table is allowed to the box drawing graphics. The order of symbols isexactly same except ALT and EXT, but they do not carry sorting information.

ISCII Plug-in

ISCII plug-in is a special program which is invoked when a browser encounters atext with MIME (Multipurpose Internet Mail Extensions) type. When the clientside browser sends a request to the server for an ISCII file with extension .isc, theserver sends the data as MIME type text. The goal of ISCII plug-in is to facilitatefull freedom to user. It uses platform independent fonts/scripts for any browser toview the Indian language contents on the web. The client end browser uses theISCII plug-in to handle input stream. ISCII plug-in converts incoming ISCII streaminto font glyph sequences for the user defined fonts. This process takes place atthe client end browser.

CHECK YOUR PROGRESS

17. The ________ are used to communicate information to the digital computerand retrieve from it.

18. Write BCD for a decimal number 599.19. To which class of codes does the gray code belong?20. What is the checksum method used for?21. What is the goal of the ISCII?

2.15 SUMMARY

In this unit, you have learned that:• A number represents a thought that refers to a precise amount of something.

Numbers can be expressed in words, gestures and symbols. Whenexpressed in words, numbers are spoken out.

• A string of digit symbols represent numbers. To find out the quantityrepresented by a number, it is essential that each digit be multiplied by aninteger power of r, and then the sum of all the weighted digits be formed.Any whole number greater than one can be used as a base in building anumeration system. The number of digits in use will always be equal to thebase.

• There are four systems of arithmetic, which are often used in digital systems.These are decimal, binary, hexadecimal and octal.

• A number system that makes use of two digits, 0 and 1, is known as thebinary number system. The binary number system is also known as basetwo system.

Page 62: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

206 Self-Instructional Material

Number System andProgramming Languages

NOTES

• The octal number system was used extensively by early minicomputers.However, for both large and small systems, it has largely been supplantedby the hexadecimal system.

• The number system which utilizes ten distinct digits, from zero to nine isknown as decimal number system.

• The hexadecimal system groups numbers by sixteen and powers of sixteen.Hexadecimal numbers are used extensively in microprocessor work.

• A binary number can be converted into decimal number by multiplying thebinary 1 or 0 by the weight corresponding to its position and adding all thevalues.

• Binary coded decimal (BCD) is one of the early memory codes. It is basedon the concept of converting each digit of a decimal number into its binaryequivalent rather than converting the entire decimal value into a pure binaryform.

• A computer code that is very widely used for data interchange is called the‘American Standard Code for International Exchange’ or ASCII. Severalcomputer manufacturers have adopted it as their computers’ internal code.

• A binary fraction can be represented by a series of 1 and 0 to the right of abinary point.

• Arithmetic operations are done in computers not by using decimal numbersas we do normally, but by using binary numbers. Arithmetic circuits incomputers and calculators perform arithmetic and logic operations. Allarithmetic operations take place in the arithmetic unit of the computer.

• A computer language is a language that can be understood by the computer.It is the computer’s native language. Computer languages serve the samepurpose as human languages. They are a means of communication.

• Language is a means of communication and a computer language is a meansof communicating with computers. It is the means to pass instructions anddata to computers. Thus, various computer languages are interfaces betweena computer and a human being.

• A code is a symbol or group of symbols that stands for something. It is arepresentation of discrete elements of information, which may be in theform of numbers, letters or any other varying physical quantities. Binarycoded decimal (BCD) uses binary number system to specify the decimalnumbers 0 to 9. It is composed of four bits.

• Indian Script Code for Information Interchange (ISCII) consists of syllables.Fonts in ISCII are defined in glyphs for Indian languages. An element ofwriting is called a glyph.

• ISCII plug-in is a special program, which is invoked when a browserencounters a text with MIME (Multipurpose Internet Mail Extension) type.

Page 63: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

Number System andProgramming Languages

NOTES

Self-Instructional Material 207

2.16 KEY TERMS

• BITS: It is the smallest element used by a computer.• Octal odometer: It is a hypothetical device similar to the odometer of a

car.• Binary coded decimal (BCD): It is based on the concept of converting

each digit of a decimal number into its binary equivalent.• Computer language: It is a means of communication with the computer.• Code: It is a symbol or group of symbols that stands for something.• Alphanumeric codes: They are codes that represent alphabetic characters

(letters), punctuation marks and other special characters.• CSP: Short for communicating sequential processes, it is a formal language

used to describe patterns of interaction concurrent systems.• ISCII Plug-In: It is a special program which is invoked when a browser

encounters a text with MIME (Multipurpose Internet Mail Extension) type.

2.17 ANSWERS TO ‘CHECK YOUR PROGRESS’

1. There are four systems of arithmetic, which are often used in digital systems.These systems are:1. Decimal2. Binary3. Hexadecimal4. Octal

2. A nibble is a group of 4 bits. This gives a maximum number of sixteenpossible different values.

3. A number system that uses eight digits, 0, 1, 2, 3, 4, 5, 6 and 7 is called anoctal number system.

4. A popular method also known as divide-by-two method, the double-dabblemethod is used to convert a large decimal number into its binary equivalent.

5. The simplest procedure is to use the binary-triplet method. The binarydigits are grouped into groups of three on each side of the binary point withzeros added on either side if needed to complete a group of three.

6. Conversion from binary to hexadecimal is easily accomplished by partitioningthe binary number into groups of four binary digits, starting from the binarypoint to the left and to the right.

Page 64: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

208 Self-Instructional Material

Number System andProgramming Languages

NOTES

7. Solution: Hexadecimal number2 A B 9

↓ ↓ ↓ ↓4 bit numbers 0010 1010 1011 . 10013 bit pattern 001 010 101 011 . 100 100

↓ ↓ ↓ ↓ ↓ ↓Octal number 1 2 5 3 . 4 4∴ [2AB.9]16 = [1253.44]8

8. Binary Coded Decimal (BCD). It is based on the concept of convertingeach digit of a decimal number into its binary equivalent rather than convertingthe entire decimal value into a pure binary form.

9. The major drawback with the BCD code is that it allows only sixty-fourdifferent characters to be represented.

10. Arithmetic operations are done in a computer not by using decimal numbers,as we do normally, but by using binary numbers.

11. 1 1 1 carry1 1 0 1 1 0 1

1 0 0 1 1 1 0

1 0 1 1 1 0 1 1

12. The most commonly used system for representing signal binary numbers isthe 2’s complement system.

13. The computer can understand only a binary-based language.14. (a) True (b) False15. Assembly language was second generation computer language.16. Java is an object-oriented programming language originally developed by

James Gosling at Sun Microsystems.17. Codes18. Solution: Decimal number → 5 5 9

↓ ↓ ↓BCD code → 0101 0101 1001

∴ [559]10 = [0101 0101 1001]BCD

19. The Gray code belongs to a class of codes called minimum change codes.20. The checksum method is used to detect double errors and pinpoint

erroneous bits.21. The goal of ISCII plug-in is to facilitate full freedom to user.

Page 65: Number System and UNIT 2 NUMBER SYSTEM AND … · Number System and Programming Languages ... to Binary Conversion 2.8.3 Double-Dabble Method; 2.8.4 Decimal Fraction to Binary 2.8.5

Number System andProgramming Languages

NOTES

Self-Instructional Material 209

2.18 QUESTIONS AND EXERCISES

Short-Answer Questions

1. Why is binary number system used in digital computers?2. Write a short note on Octal Number System?3. Convert [854]10 to hexadecimal number.4. Write a short note on how binary addition is performed.5. Write a short note on checksum.

Long-Answer Questions

1. How would you perform a binary to decimal conversion?2. Explain floating point representation of numbers.3. Perform the subtraction using 1’s complement addition of the following binary

numbers: 110010–101101, 111001010–110110101, 11010101–101011004. List the high-level languages along with their description.5. Explain the ISCII codes with its features.

2.19 FURTHER READING

Lipschutz, Martin M. Schaum’s Outline of Theory and Problems of DataProcessing. New York: Mc-Graw Hill.

Ram, B. Computer Fundamentals. New Delhi: New Age International.Sanders, H. Donald. Computers Today. New York: McGraw-Hill.