What Is ASCII (American Standard Code For Information Interchange)?

How does ASCII work?

ASCII offers a universally accepted and understood character set for basic data communications. The format codes a string of data as ASCII characters that can be interpreted and displayed as readable plain text for people and as data for computers.

Programmers use the design of the ASCII character set to simplify certain tasks. For example, using ASCII character codes, changing a single bit easily converts text from uppercase to lowercase.

The capital letter "A" is represented by the binary value:

0100 0001

The lowercase letter "a" is represented by the binary value:

0110 0001

The difference is the third most significant bit. In decimal and hexadecimal, this corresponds to:

Character Binary Decimal Hexadecimal
A 0100 0001 65 41
a 0110 0001 97 61

The difference between uppercase and lowercase characters is always 32 (0x20 in hexadecimal), so converting from uppercase to lowercase and back is a matter of adding or subtracting 32 from the ASCII character code.

Similarly, hexadecimal characters for the digits 0 through 9 are as follows:

Character Binary Decimal Hexadecimal
0 0011 0000 48 30
1 0011 0001 49 31
2 0011 0010 50 32
3 0011 0011 51 33
4 0011 0100 52 34
5 0011 0101 53 35
6 0011 0110 54 36
7 0011 0111 55 37
8 0011 1000 56 38
9 0011 1001 57 39

Using this encoding, developers can easily convert ASCII digits to numerical values by stripping off the four most significant bits of the binary ASCII values (0011). This calculation can also be done by dropping the first hexadecimal digit or by subtracting 48 from the decimal ASCII code.

Developers can also check the most significant bit of characters in a sequence to verify that a data stream, string or file contains ASCII values. The most significant bit of basic ASCII characters will always be 0; if that bit is 1, then the character is not an ASCII-encoded character.

Tag » What Is An Extended Character