ASCII Code

Binary System

The binary system is a number system that only uses digits 0 and 1. Whereas the decimal system counts to 9 before adding a second digit, binary numbers reach two digits after 1. The binary system is the native number system for computers.

Counting in Binary
0 = 0000
1 = 0001
2 = 0010
3 = 0011
4 = 0101
5 = 0101
6 = 0110
7 = 0111
8 = 1000
9 = 1001
10 = 1010
11 = 1011
12 = 1100
13 = 1101
14 = 1110
15 = 1111
Adding in Binary


     8    1000
   + 6    0110
   ---    ----
    14    1110

11 1011
+ 2 0010
— —-
13 1101

Binary numbers that are 8-bit (8 digits of 0/1) can store decimal numbers from 0 to 255. 16-bit binary numbers allow from 0 to 65,535.

ASCII and Unicode


When computers store characters (letters, numbers, and symbols), they do so with numeric representation. Each letter in the alphabet has a standard code. These codes are established in a standard called ASCII (American Standard Code for Information Interchange).

The ASCII standard only allows for 255 characters. This can be a problem in east Asia because the alphabet includes thousands of unique characters. Unicode was developed because of the limits of ASCII; it represents almost every character and every symbol in every language as a number from 0 to 65,535.

The ASCII Chart can be found in the Visual Basic help files. Click on Help and choose Help Topics. Find the section on Additional Information and look at the Character Sets.

Asc Function


The Asc function returns the ASCII code corresponding to a character.

Syntax

Asc(string)
string is a variable or string containing a single character.
Example 1
Dim intCode As Integer
intCode = Asc("A")
MsgBox intCode

Example 1 displays the number 65 in a message box, since 65 is the ASCII code for a capital letter “A”.

Chr Function

The Chr function returns the character represented by the specified ASCII code.

Syntax

Chr(integer)
integer is a number from 0 to 255.
Example 2
Dim strChar As String
strChar = Chr(66)
MsgBox strChar

Example 2 displays the capital letter “B” in a message box, since 66 is the ASCII code for “B”.