ASCII Table – Print ASCII Codes, Characters and Symbols by a Computer Program

ASCII Characters

ASCII stands for American Standard Code for Information Interchange. It is a character encoding standard that represents characters such as letters, numbers, and symbols as numbers between 0 and 127. ASCII codes are used to represent text in computers and other devices.

It is a 7-bit character code where each individual bit represents a unique character. So a maximum of 128 characters are represented in ASCII Standard which first 32 are control characters which were designed to control computer hardware. These are the standard characters used for most computer systems.

List of all ASCII Characters and Description

Decimal NumberOCT NumberHEX NumberBIN NumberSymbolDescription
0000000000000NULNull character
1001010000001SOHStart of Heading
2002020000010STXStart of Text
3003030000011ETXEnd of Text
4004040000100EOTEnd of Transmission
5005050000101ENQEnquiry
6006060000110ACKAcknowledge
7007070000111BELBell, Alert
8010080001000BSBackspace
9011090001001HTHorizontal Tab
100120A0000101LFLine Feed
110130B0001011VTVertical Tabulation
120140C0001100FFForm Feed
130150D0001101CRCarriage Return
140160E0001110SOShift Out
150170F0001111SIShift In
16020100010000DLEData Link Escape
17021110010001DC1Device Control One (XON)
18022120010010DC2Device Control Two
19023130010011DC3Device Control Three (XOFF)
20024140010100DC4Device Control Four
21025150010101NAKNegative Acknowledge
22026160010110SYNSynchronous Idle
23027170010111ETBEnd of Transmission Block
24030180011000CANCancel
25031190011001EMEnd of medium
260321A0011010SUBSubstitute
270331B0011011ESCEscape
280341C0011100FSFile Separator
290351D0011101GSGroup Separator
300361E0011110RSRecord Separator
310371F0011111USUnit Separator
32040200100000SPSpace character
33041210100001!exclamation mark
34042220100010quotation mark
35043230100011#number sign
36044240100100$dollar currency sign
37045250100101%percent sign
38046260100110&Ampersand (also used as and)
39047270100111Apostrophe (also known as single quote)
40050280101000(left parenthesis
41051290101001)right parenthesis
420522A0101010*asterisk
430532B0101011+plus sign
440542C0101100,comma
450552D0101101hyphen
460562E0101110.period
470572F0101111/slash
480603001100000number 0
490613101100011number 1
500623201100102number 2
510633301100113number 3
520643401101004number 4
530653501101015number 5
540663601101106number 6
550673701101117number 7
560703801110008number 8
570713901110019number 9
580723A0111010:colon
590733B0111011;semicolon
600743C0111100<less-than
610753D0111101=equals-to
620763E0111110>greater-than
630773F0111111?question mark
64100401000000@at sign
65101411000001Auppercase letter A
66102421000010Buppercase letter B
67103431000011Cuppercase letter C
68104441000100Duppercase letter D
69105451000101Euppercase letter E
70106461000110Fuppercase letter F
71107471000111Guppercase letter G
72110481001000Huppercase letter H
73111491001001Iuppercase letter I
741124A1001010Juppercase letter J
751134B1001011Kuppercase letter K
761144C1001100Luppercase letter L
771154D1001101Muppercase letter M
781164E1001110Nuppercase letter N
791174F1001111Ouppercase letter O
80120501010000Puppercase letter P
81121511010001Quppercase letter Q
82122521010010Ruppercase letter R
83123531010011Suppercase letter S
84124541010100Tuppercase letter T
85125551010101Uuppercase letter U
86126561010110Vuppercase letter V
87127571010111Wuppercase letter W
88130581011000Xuppercase letter X
89131591011001Yuppercase letter Y
901325A1011010Zuppercase letter Z
911335B1011011[left square bracket
921345C1011100\backslash
931355D1011101]right square bracket
941365E1011110^caret
951375F1011111_underscore
96140601100000`grave accent
97141611100001alowercase letter a
98142621100010blowercase letter b
99143631100011clowercase letter c
100144641100100dlowercase letter d
101145651100101elowercase letter e
102146661100110flowercase letter f
103147671100111glowercase letter g
104150681101000hlowercase letter h
105151691101001ilowercase letter i
1061526A1101010jlowercase letter j
1071536B1101011klowercase letter k
1081546C1101100llowercase letter l
1091556D1101101mlowercase letter m
1101566E1101110nlowercase letter n
1111576F1101111olowercase letter o
112160701110000plowercase letter p
113161711110001qlowercase letter q
114162721110010rlowercase letter r
115163731110011slowercase letter s
116164741110100tlowercase letter t
117165751110101ulowercase letter u
118166761110110vlowercase letter v
119167771110111wlowercase letter w
120170781111000xlowercase letter x
121171791111001ylowercase letter y
1221727A1111010zlowercase letter z
1231737B1111011{left curly brace
1241747C1111100|vertical bar (also known as pipe sign)
1251757D1111101}right curly brace
1261767E1111110~Tilde sign
1271777F1111111DELDelete

C Program to Print ASCII Characters

This program prints the ASCII character table. The program displays each character’s Decimal, Octal, Hexadecimal, Binary, and Symbol representation. It uses a loop to iterate through all 128 ASCII values (0 to 127) and formats the output into neatly aligned columns. This is very handy C function for many programmers.

The program also, replaces non-printable ASCII characters (values 0–31 and 127) with a blank space (' ') to avoid displaying unprintable symbols.

#include <stdio.h>

void printBinary(int num, char *binStr) {
    for (int i = 7; i >= 0; i--) {
        binStr[7 - i] = (num & (1 << i)) ? '1' : '0';
    }
    binStr[8] = '\0'; // Null-terminate the string
}

int main() {
    printf("Decimal Number\tOCT Number\tHEX Number\tBIN Number\tSymbol\n");

    for (int i = 0; i < 128; i++) {
        char bin[9]; // Array to hold the binary string (8 bits + null terminator)
        printBinary(i, bin);

        // Replace non-printable characters with a blank space
        char symbol = (i >= 32 && i <= 126) ? i : ' ';

        printf("%d\t\t%03o\t\t%02X\t\t%s\t\t%c\n", i, i, i, bin, symbol);
    }

    return 0;
}

C++ Program to Print ASCII Characters

This C++ program generates and displays the ASCII character table in a structured format. It lists each ASCII character’s Decimal, Octal, Hexadecimal, Binary, and Symbol representations. The program is designed to iterate through all 128 ASCII values (from 0 to 127) and outputs the information in aligned columns for readability.

#include <iostream>
#include <iomanip>
#include <bitset>
using namespace std;

int main() {
    // Print the header
    cout << "Decimal Number\tOCT Number\tHEX Number\tBIN Number\tSymbol" << endl;

    for (int i = 0; i < 128; i++) {
        // Binary representation using std::bitset
        string binary = bitset<8>(i).to_string();

        // Replace non-printable characters with a space
        char symbol = (i >= 32 && i <= 126) ? static_cast<char>(i) : ' ';

        // Print the row
        cout << setw(15) << i                // Decimal number
             << setw(10) << oct << i         // Octal number
             << setw(10) << hex << uppercase << i  // Hexadecimal number
             << setw(15) << binary           // Binary number
             << setw(10) << symbol           // Symbol
             << endl;

        // Reset output stream formatting
        cout << dec; // Ensure decimal formatting is restored
    }

    return 0;
}

Python Program to Print ASCII Characters

The program uses Python’s format function to convert each ASCII value into an 8-bit binary representation.

# Function to generate an 8-bit binary representation
def to_binary(num):
    return format(num, '08b')

# Print the header
print(f"{'Decimal Number':<15}{'OCT Number':<12}{'HEX Number':<12}{'BIN Number':<12}{'Symbol':<10}")

# Iterate through all 128 ASCII characters
for i in range(128):
    decimal = i  # Decimal representation
    octal = format(i, '03o')  # Octal representation
    hexadecimal = format(i, '02X')  # Hexadecimal representation in uppercase
    binary = to_binary(i)  # Binary representation
    symbol = chr(i) if 32 <= i <= 126 else ' '  # Display symbol or blank for non-printable characters
    
    # Print the row
    print(f"{decimal:<15}{octal:<12}{hexadecimal:<12}{binary:<12}{symbol:<10}")

C# Program to Print ASCII Characters

using System;

class AsciiTable
{
    // Method to convert an integer to 8-bit binary string
    public static string ToBinary(int num)
    {
        return Convert.ToString(num, 2).PadLeft(8, '0');
    }

    public static void Main()
    {
        // Print the header
        Console.WriteLine("{0,-15}{1,-12}{2,-12}{3,-12}{4,-10}", 
                          "Decimal Number", "OCT Number", "HEX Number", "BIN Number", "Symbol");

        // Iterate through all 128 ASCII characters
        for (int i = 0; i < 128; i++)
        {
            int decimalValue = i;  // Decimal representation
            string octal = Convert.ToString(i, 8);  // Octal representation
            string hexadecimal = Convert.ToString(i, 16).ToUpper();  // Hexadecimal representation in uppercase
            string binary = ToBinary(i);  // Binary representation
            // Display symbol or blank for non-printable characters
            string symbol = (i >= 32 && i <= 126) ? ((char)i).ToString() : " ";  

            // Print the row with proper formatting
            Console.WriteLine("{0,-15}{1,-12}{2,-12}{3,-12}{4,-10}", 
                              decimalValue, octal, hexadecimal, binary, symbol);
        }
    }
}

Output of the Programs:

References

M. Saqib: Saqib is Master-level Senior Software Engineer with over 14 years of experience in designing and developing large-scale software and web applications. He has more than eight years experience of leading software development teams. Saqib provides consultancy to develop software systems and web services for Fortune 500 companies. He has hands-on experience in C/C++ Java, JavaScript, PHP and .NET Technologies. Saqib owns and write contents on mycplus.com since 2004.
Related Post