Saturday, May 23, 2009

ANSI Vs UNICODE

ANSI and UNICODE are the standard of storing data.

ANSI stands for American National Standards Institute. One of the ANSI standards is ASCII (American Standard Code for Information Interchange) which consists of letters, numbers, and symbols that a computer uses. ANSI character set consists of 256 different characters and each character is represented by a single byte in memory.

Example: Technically when you save any string (say student), it will store in ANSI format as:

char szString[8]=”student”;

Byte 0 1 2 3 4 5 6 7
string s t u d e n t null

However many languages have more than 256 characters and ANSI encoding cannot support so much of characters. To overcome this limitation, engineers designed a character set called UNICODE, which can hold any language. UNIOCDE supports around 10,000 characters and each character is represented by two bytes in memory.

Lets consider same example

wchar_t szString[16]=_T("student");

Byte 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
string s . t . u . d . e . n . t . null null