ASCII – ASCII table

1. What is the ASCII code?

ACSI (American Standard Code for Information Interchange – Ascii information USA), often pronounced ace-fiber-ki, the character and the character code based on the Latin alphabet used in modern English and other Western European languages. It is often used to display text in computers and other information devices. It is also used by the control device working with text. (theo wiki).

Thus each one character we will have a corresponding identification number as the table below.

ASCII code table

In which you pay attention to some special code:

  • 65 A
  • 97 is a
  • 48 is number 0

2. Code ASCII code generation

The program is written in C ++ by Dev-nguyenvanquan7826.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>

void gotoxy(int x, int y)   // xay dung ham gotoxy
{
  static HANDLE h = NULL;
  if(!h)
    h = GetStdHandle(STD_OUTPUT_HANDLE);
  COORD c = { x, y };
  SetConsoleCursorPosition(h,c);
}

void SetColor(WORD color)
{
    HANDLE hConsoleOutput;
    hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);

    CONSOLE_SCREEN_BUFFER_INFO screen_buffer_info;
    GetConsoleScreenBufferInfo(hConsoleOutput, &screen_buffer_info);

    WORD wAttributes = screen_buffer_info.wAttributes;
    color &= 0x000f;
    wAttributes &= 0xfff0;
    wAttributes |= color;

    SetConsoleTextAttribute(hConsoleOutput, wAttributes);
}

int main(){
    int a[256] = {0};
    a[7] = a[8] = a[9] = a[10] = a[13] = 1;
    char *s = "ASCII table upload by nguyenvanquan7826";
    gotoxy(40 - strlen(s)/2, 1);
    printf("%s\n\n", s);
    system("color 1A");   // Dat mau, mau nen la 1, mau chu la A
    for (int i=0; i<20; i++){
        for (int j=i, k = 0; k<13 && j<256; k++, j += 20){
            //SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 5);
            SetColor(10);
            printf("%4d ", j);
            SetColor(15);
            if (a[j])
                printf(" ");
            else
                printf("%c", j);
        }

        printf("\n");
    }
    SetColor(10);
    s = "Program in Dev-C++";
    gotoxy(40 - strlen(s)/2, 24);
    printf("%s\n\n", s);
}