Showing posts with label Number System. Show all posts
Showing posts with label Number System. Show all posts

ASCII CODE TUTORIALS


WHAT IS THE ASCII CODE?

The ASCII (American Standard Code for Information Interchange), pronounced ‘ask-ee’, is strictly a seven-bit code based on the English alphabet. ASCII codes are used to represent alphanumeric data in computers, communications equipment and other related devices. The code was first published as a standard in 1967.

It was subsequently updated and published as ANSI X3.4-1968, then as ANSI X3.4-1977 and finally as ANSI X3.4-1986. Since it is a seven-bit code, it can at the most represent 128 characters.

It currently defines 95 printable characters including 26 upper-case letters (A to Z), 26 lower-case letters (a to z), 10 numerals (0 to 9) and 33 special characters including mathematical symbols, punctuation marks and space character.

In addition, it defines codes for 33 nonprinting, mostly obsolete control characters that affect how text is processed. With the exception of ‘carriage return’ and/or ‘line feed’, all other characters have been rendered obsolete by modern mark-up languages and communication protocols, the shift from text-based devices to graphical devices and the elimination of teleprinters, punch cards and paper tapes.

An eight-bit version of the ASCII code, known as US ASCII-8 or ASCII-8, has also been developed. The eight-bit version can represent a maximum of 256 characters.

Table 2.6 lists the ASCII codes for all 128 characters. When the ASCII code was introduced, many computers dealt with eight-bit groups (or bytes) as the smallest unit of information.

The eighth bit was commonly used as a parity bit for error detection on communication lines and other device-specific functions. Machines that did not use the parity bit typically set the eighth bit to ‘0’.

ASCII CODE TABLE




Looking at the structural features of the code as reflected in Table 2.6, we can see that the digits 0 to 9 are represented with their binary values prefixed with 0011. That is, numerals 0 to 9 are represented by binary sequences from 0011 0000 to 0011 1001 respectively.

Also, lower-case and upper-case letters differ in bit pattern by a single bit. While upper-case letters ‘A’ to ‘O’ are represented by 0100 0001 to 0100 1111, lower-case letters ‘a’ to ‘o’ are represented by 0110 0001 to 0110 1111.

Similarly, while upper-case letters ‘P’ to ‘Z’ are represented by 0101 0000 to 0101 1010, lower-case letters ‘p’ to ‘z’ are represented by 0111 0000 to 0111 1010. With widespread use of computer technology, many variants of the ASCII code have evolved over the years to facilitate the expression of non-English languages that use a Roman-based alphabet.

In some of these variants, all ASCII printable characters are identical to their seven-bit ASCII code representations. For example, the eight-bit standard ISO/IEC 8859 was developed as a true extension of ASCII, leaving the original character mapping intact in the process of inclusion of additional values.

This made possible representation of a broader range of languages. In spite of the standard suffering from incompatibilities and limitations, ISO-8859-1, its variant Windows-1252 and the original seven-bit ASCII continue to be the most common character encodings in use today.

PACKED AND UNPACKED BINARY CODED DECIMAL (BCD) NUMBERS


WHAT ARE PACKED AND UNPACKED BINARY CODED DECIMAL (BCD) NUMBERS

In the case of unpacked BCD numbers, each four-bit BCD group corresponding to a decimal digit is stored in a separate register inside the machine. In such a case, if the registers are eight bits or wider, the register space is wasted.

In the case of packed BCD numbers, two BCD digits are stored in a single eight-bit register. The process of combining two BCD digits so that they are stored in one eight-bit register involves shifting the number in the upper register to the left 4 times and then adding the numbers in the upper and lower registers.

The process is illustrated by showing the storage of decimal digits ‘5’ and ‘7’:

• Decimal digit 5 is initially stored in the eight-bit register as: 0000 0101.

• Decimal digit 7 is initially stored in the eight-bit register as: 0000 0111.

• After shifting to the left 4 times, the digit 5 register reads: 0101 0000.

• The addition of the contents of the digit 5 and digit 7 registers now reads: 0101 0111.

Example 
How many bits would be required to encode decimal numbers 0 to 9999 in straight binary and BCD codes? What would be the BCD equivalent of decimal 27 in 16-bit representation?

Solution

• Total number of decimals to be represented=10 000=104 =213 29.

• Therefore, the number of bits required for straight binary encoding=14.

• The number of bits required for BCD encoding=16.

• The BCD equivalent of 27 in 16-bit representation=0000000000100111.

HEXADECIMAL NUMBER SYSTEM TUTORIALS


WHAT IS THE HEXADECIMAL NUMBER SYSTEM?


The hexadecimal number system is a radix-16 number system and its 16 basic digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E and F. The place values or weights of different digits in a mixed hexadecimal number are 160, 161, 162 and so on (for the integer part) and 16−1, 16−2, 16−3 and so on (for the fractional part).
 The decimal equivalent of A, B, C, D, E and F are 10, 11, 12, 13, 14 and 15 respectively, for obvious reasons.

The hexadecimal number system provides a condensed way of representing large binary numbers stored and processed inside the computer. One such example is in representing addresses of different memory locations. Let us assume that a machine has 64K of memory.

Such a memory has 64K (= 216 = 65 536) memory locations and needs 65 536 different addresses. These addresses can be designated as 0 to 65 535 in the decimal number system and 00000000 00000000 to 11111111 11111111 in the binary number system.

The decimal number system is not used in computers and the binary notation here appears too cumbersome and inconvenient to handle. In the hexadecimal number system, 65 536 different addresses can be expressed with four digits from 0000 to FFFF.

Similarly, the contents of the memory when represented in hexadecimal form are very convenient to handle.