Skip to content

Instantly share code, notes, and snippets.

@thomasjao
Created August 7, 2017 05:38
Show Gist options
  • Save thomasjao/ef6a379733e5c8365a0a14256c6dcbb4 to your computer and use it in GitHub Desktop.
Save thomasjao/ef6a379733e5c8365a0a14256c6dcbb4 to your computer and use it in GitHub Desktop.
Generate ASCII Table in 4 columns
#include <stdio.h>
int main(void)
{
int i, col, code;
char* char_name[32];
char_name[0] = "NUL";
char_name[1] = "SOH";
char_name[2] = "STX";
char_name[3] = "ETX";
char_name[4] = "EOT";
char_name[5] = "ENQ";
char_name[6] = "ACK";
char_name[7] = "BEL";
char_name[8] = "BS";
char_name[9] = "TAB";
char_name[10] = "LF";
char_name[11] = "VT";
char_name[12] = "FF";
char_name[13] = "CR";
char_name[14] = "SO";
char_name[15] = "SI";
char_name[16] = "DLE";
char_name[17] = "DC1";
char_name[18] = "DC2";
char_name[19] = "DC3";
char_name[20] = "DC4";
char_name[21] = "NAK";
char_name[22] = "SYN";
char_name[23] = "ETB";
char_name[24] = "CAN";
char_name[25] = "EM";
char_name[26] = "SUB";
char_name[27] = "ESC";
char_name[28] = "FS";
char_name[29] = "GS";
char_name[30] = "RS";
char_name[31] = "US";
printf("DEC\tHEX\tOCT SYMBOL\t\tDEC\tHEX\tOCT SYMBOL\t\tDEC\tHEX\tOCT SYMBOL\t\tDEC\tHEX\tOCT SYMBOL\n");
printf("==============================\t\t==============================\t\t==============================\t\t==============================\t\t\n");
for ( i = 0; i < 32; i++ ) {
for ( col = 0; col < 4; col++ ) {
code = 32 * col + i;
if ( col == 0 ) {
printf("%3d\t%2X\t%2o\t%s\t\t", code, code, code, char_name[code]); // Control characters
} else
printf("%3d\t%2X\t%2o\t%c\t\t", code, code, code, code); // Other characters
}
printf("\n");
}
}
@thomasjao
Copy link
Author

ASCII TABLE

ASCII is the most fundamental character coding map for information technology as well as some engineering technologies. It is also a basic table for other coding method, such as UTF-8.

In general, we represent the codes in DECimal, HEXadecimal and OCTal forms, and name the characters represents "SYMBOL", for not all codes represent characters. Instead, some of them are "Control Characters" which are not printable, they are used to control some data transmission mechanism, or rendering on screen.

Those codes under decimal 32 are control codes. Please refer following list:

Dec Hex SYMBOL Description
0 0 NULL Null (nothing, used to terminate something or symbolize idle
1 1 SOH Start of Heading, for data communication preamble
2 2 STX Start of Text, Following data are TEXT data
3 3 ETX End of Text. Trail the TEXT data to indicate end of data.
4 4 EOT End of Transmission. Trail the whole data to indicate end of transmission.
5 5 ENQ Enquiry. Means the issuer need some response from the other side.
6 6 ACK Acknowledge. Means recognize reception of transmitted data, before any error corrections.
7 7 BEL Bell. Make bell "ding" on the machine.
8 8 BS Backspace. To backspace ONE position to previous position.
9 9 TAB Horizontal tab. Push cursor forward n position right to current position.
<span #style="color:red">10 A LF Line Feed. Send cursor to next line.
11 B VT Vertical Tab. Send cursor to same position of next line.
12 C FF Form Feed. Send cursor to new page.
13 D CR Carriage Return. Send cursor to start of line.
14 E SO Shift out.
15 F SI Shift in.
16 10 DLE Data Link Escape.
17 11 DC1 Device Control 1.
18 12 DC2 Device Control 2.
19 13 DC3 Device Control 3
20 14 DC4 Device Control 4
21 15 NAK Negative Acknowledge.
22 16 SYN Synchronous idel.
23 17 ETB End of Frame, or Block.
24 18 CAN Cancel
25 19 EM. End of Medium.
26 1A SUB Substitute
27 1B ESC Escape
28 1C FS File Separator
29 1D GS Group Separator
30 1E RS Record Separator
31 1F US Unit Separator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment