Computer Codes and Computer Arithmetic

 The previous chapter deals with pure binary numbers. The goal of this chapter is to present the formats used in computer memory to record data. We will see how these binary numbers are coded to represent characters in the computer memory.

Numeric data is not the only form of data that is to be handled. We often require to process alphanumeric data. An alphanumeric data is a string of symbols where a symbol may be one of the letters from A...Z, 0.9 or a special character (*,&,^,%,$,+,-) etc.

  Byte

In binary coding, every symbol that appears in the data is represented by a group of bits. The group of bits use to represent a symbol is called a byte. To indicate the number of bits in a group, sometimes a byte is referred as an n-bit byte where group contains n bits. However, the term byte is commonly used to mean an 8-bit byte because most of the modern computers use 8 bits to represent a symbol. Thus a byte is comprised of 8 bits.

Thus

1 byte = 8 bits

1 kilobyte = 1024 bytes

1 megabyte =1024 kilobyte (KB)

1 Gigabyte = 1024 megabyte (MB)

A floppy has a capacity of 1.44 MB

A hard disk varies from 10 GB to 40 GB nowadays. 

BCD code

The binary coded decimal (BCD) is one of the early memory codes. It is based on the idea of converting each digit of a decimal number into its idea of converting each digit of a decimal number into its binary equivalent rather than converting the entire decimal value into a pure binary. The BCD equivalent of each decimal digit is shown in table below. Since 8 and 9 require 4 bits, all decimal digits are represented in BCD by 4 bits. The pure binary equal of 4210 = 1010102. Converting 4210 into BCD, however, produces the following result:

4210= 0100 (binary equal for 4) 0010 (binary equal for 2)

or 01000010 in BCD.

Note :

  1. Each decimal digit is independently converted to a 4 bit binary number and hence the conversion process is very easy.
  2. When 4 bits are used, altogether 16 configurations are possible 24 = 16.

BCD equivalent of decimal digits

Decimal digit

BCD equivalent

0

0000

1

0001

2

0010

3

0011

4

0100

5

0101

6

0110

7

0111

8

1000

9

1001

 

You can see that only the first 10 of these combinations are used to represent decimal digits. The remaining 6 arrangements as given in table below are not used in BCD coding.

Decimal

Binary equal

10

1010

11

1011

12

1100

13

1101

14

1110

15

1111

 

That is, 1010 does not represent 1010 in BCD.

Instead

1010 = 0001          0000
1                              0

OR 00010000 in BCD

In the above discussion, we have used a group of 4 bits to represent a digit (character) in BCD. 4-bit BCD coding system can be used to represent only decimal numbers because 4 bits are insufficient to represent the various characters used by a computer. Instead of using 4 bits with only 16 possible characters, computer designers commonly use 6 bits to represent characters in BCD code.

In the 6-bit BCD code, the four BCD numeric place positions are retained but the two additional zone positions are added. With 6 bits, it is possible to represent 64 (26) different characters. This is a sufficient number to code the decimal digits (0-9, 10), letters (A-Z, 26) and other special characters (28).

Example:

Show the binary digits used to record the word BASE

B =110010
A=110001
S=010010
E=110101

So the binary digit

110010                  110001                  010010                  110101
     B                             A                            S                              E

Will record the word BASE in BCD.

EBCDIC Extended Binary Coded Decimal Interchange Code

The major problem with BCD code is that only 64 (26) different characters can be represented in it. This is not sufficient for providing decimal number (10), lowercase letters (26), uppercase letters (26) and a fairly large number of special characters (28+).

Hence the BCD code was extended from a 6-bit code to an 8-bit code. The added 2 bits are used as additional zone bits, expanding the zone bits to 4 bits. The resulting code is called the extended binary coded decimal interchange code (EBCDIC). In this code it is possible to represent 256 (28) different characters instead of 64 (26). In addition to the various character requirements mentioned above, this also allows a large variety of printable characters and several non-printable control characters. The control characters are used to control such activities as printer vertical spacing, movement of cursor on the terminal screen etc. All the 256 bit combinations have not yet been assigned characters, so the code can still grow as new requirements develop.

 Because EBCDIC is an 8-bit code, it can be easily divided into two 4-bit groups .Each of these 4-bit groups can be represented by 1 hexadecimal digit. Thus the hexadecimal number system is used a short cut notation for memory dump by computers that use EBCDIC for internal representation of characters. Developed by IBM, EBCDIC code is used in most IBM models and in many other computers.

ASCII (American standard code for information interchange)

Another computer code that is very widely used is the ASCII (American Standard Code for Information Interchange). Several American computer manufacturers have adopted ASCII as their computer's internal code. This code is popular in data communication, is used almost exclusively to represent data internally in microcomputers, and is frequently found in the larger computers produced by some vendor.

ASCII is of two types: ASCII-7 and ASCII-8.

ASCII -7 is a 7 bit code that allows 128 (27) different characters. The first 3 bits are used as zone bits and the last four bits indicate the digit. ASCII-8 is an extended version of ASCII-7. It is an 8-bit code that allows 256 (28) different characters rather than 128.

Computer arithmetic

Why a computer can understand only binary language?

Information is handled in the computer by electronic /electrical components such as transistors, semiconductors, wires etc. All these components can only indicate two states or conditions on (1) off (0).

  1. Transistors are either conducting (1) or non-conducting (0)
  2.  Magnetic materials are either magnetized (1) or non-magnetized (0)
A pulse or voltage is either present (1) or absent (0).

All information is represented within the computer by the presence or absence system, which has only two digits (0 and 1), is most suitable and is conveniently used to express the two possible states.

Besides, the computer circuits only have to handle two binary digits rather than ten decimal digits. The result is that the internal circuit design of computers is simplified to a great extent. This ultimately results in less expensive and more reliable circuits for computers.

Binary arithmetic

Addition

Binary addition is performed in the same manner as decimal addition. The complete table for binary addition is as follows:

0 + 0 = 0

0 + 1 = 1

1 + 0 = 1

1 + 1 = 0 plus a carry of 1 to next higher column.

Carry-overs are performed in the same manner as in decimal arithmetic. Since 1 is the largest digit in the binary system, any sum greater than 1 requires that a digit be carried over. For example 10 plus 10 binary requires the addition of two l's in the second position. Since 1 + 1 = 0 plus a carry-over of 1, the sum of 10 + 10 is 100 in binary.

Example 1: Add 101 and 10

101
+10
111

 Example 2: Add 101 and 11

Carry     111
101
+11
1000

 Example 3: Add binary number 100111 and 11011.

 Carry    11111

100111

+11011

1000010

In this we face a new situation (1+1+1) brought about by the carry-over of 1 in the second column. This can also be handled using the same four rules for binary addition. The addition of three 1's can be broken up into two steps.

  1. First we add only two 1's giving 10.
  2. In Second step we add 1 to 10 getting 11 as the result.

Subtraction

The principles of decimal subtraction can as well be applied to subtraction of numbers in other baese. It consists of four rules

0-0 = 0

 1-0 = 1

1-1 = 0

0-1 = 1 with a borrow from the next column.

Thus as in decimal 10 is borrowed, in binary 2 is borrowed, in octal 8 is borrowed and in hexadecimal 16 is borrowed.

Example 4: subtract 011102 from 101012

Solution:

12

Borrow 0202

10101 (2110 in decimal)

- 01110 (1410 in decimal)

   00111 (710 in decimal)

The final result of subtraction is 001112

Additive method of subtraction

The direct method of subtraction using borrowing is easy on paper and pencil. But when subtraction is performed by digital components, this method becomes less efficient and we use another methods known as complementary subtraction method.

What is a complement?

Complement of a number is defined as the difference between the number and the base raised to the nth power minus one, where n is the number of digits in a number.

Complement of x = [(base)" - 1] - X

Example 5: Find the complement of 57.

Solution

Complement =[(10)2 - 1] - 57

=[100 – 1] -57

=99 – 57

 =42

Thus, the complement of 5710 = 4210.

But in binary numbers, it is not necessary to go through the usual process of obtaining complement. Instead, a quick way is used where a complement of a binary number is obtained by transforming all its "0" to "1" and "1" to "0". For example the complement of 1011010 is 0100101. This circuit for obtaining complement of a number in binary system can be easily designed at very less expense.

Subtraction by complementary method

Subtraction by complementary method involves the following three steps.

  1. Find the complement of the number you are subtracting (subtrahend)
  2. Add this to the number from which you are taking away.
  3. If there is a carry of 1, add it to obtain the result; if there is no carry, recomplement the sum and attach a negative sign to obtain the result.

Example 6: subtract 0111000 (5610) from 1011100 (9210) using complementary method.

Solution:

Step 1: complement of 0111000 is 1000111

Step 2: add the complement to the minuend (1011100)

1011100

+1000111 (complement of 0111000)

10100011 (result of sum)

Step 3: add the carry to the result of sum.

0100011 (result of sum)

____→_1 (add the carry of 1)

0100100

Result is 01001002= 3610

Multiplication

Multiplication in binary arithmetic follows four rules.

1 x 0=0

0 x 1=0

1 x 0=0

1 x 1=1

The method is illustrated by an example.

Example 8: multiply 1010 by 1001.

      1010
   x 1001
      1010
    0000x
  0000xx
1010xxx
1011010 final product

Division

Binary division is again very simple. As in the decimal, division by zero is meaning less. Hence the complete table for binary division is as follows:

0 / 1=0

1/ 1 =1

The division process is performed in a manner similar to decimal division. The rules for binary division are as follows.

  1.  Start from the left of the dividend.
  2. Perform a series of subtractions in which the divisor is subtracted from the dividend.
  3.  If subtraction is possible put a 1 in the quotient and subtract from the corresponding digits of dividend. 
  4. If subtraction is not possible (divisor greater than remainder), record a 0 in the quotient.
  5. Bring down the next digit to add to the remainder digits.
  6. Proceed as before in a manner similar to long division.

 Example 9:

110/100001\ 0101 ( quotient)
        110 (step 1)
        1000 (step 2)
          110 (step 3)
            100 (step 4)
            110 (step 5)
            1001 (step 6)
              110 (step 7)
                11 (remainder)

 Description of steps:

  1. Divisor greater than 100, so put a 0 in quotient.
  2.  Add digit from dividend to group used above.
  3. Subtraction possible so put 1 in quotient.
  4. Remainder from subtraction plus digit from dividend.
  5. Divisor greater so put a 0 in quotient. 6. Add digit from dividend to group.
  6.  Subtraction possible so put 1 in quotient.

Share:

0 comments:

Post a Comment

Popular Posts

Recent Posts

Share This:

Categories

Unordered List

3/recent/post-list

Pages


Please Sign In

Sign out