C++ Program to find ASCII value of Character and Vice Versa

     ASCII stands for American Standard Code for Information Interchange. It is an encoding standard mainly deals with electronic communication.

Letters, digits and special characters are assigned with unique ASCII code.

How it started?

 In 1963, the first edition was developed from telegraph code.  Subsequent revisions in 1967 and 1986.

ASCII character Set:

It has 128 characters. It has unique seven-bit binary code. These characters include printable and control characters.

For eg : null charcter  - it is represented by 0 00000000

For ‘A’, the ascii value is 65. It’s binary code is 01000001.

It is world widely accepted character encoding. The upgraded version includes additional 128 characters.

Let us create two c++ programs to convert ascii value into character and character into ascii value.

C++ program to find ASCII Value of a character:

#include <iostream>

using namespace std;

int main() {

    char ch;

    cout << "Enter a character: ";

    cin >> ch;

    // Display ASCII value

    cout << "The ASCII value of '" << ch << "' is " << int(ch) << endl;

    return 0;

}

Output:

Here, comes the output.

Enter a character: B

The ASCII value of 'B' is 66

Enter a character: &

The ASCII value of '&' is 38

C++ program to find ASCII Value of a Character:

#include <iostream>

#include <string>

using namespace std;

int main() {

    int ascii_value;

    char ch;

    cout << "Enter the ascii value: ";

    cin >> ascii_value;

    ch = static_cast<char>(ascii_value);

    // Display character value

    cout << "The character value of '" << ascii_value << "' is " << ch << endl;

    return 0;

}

Output:

Compile and run the program to get the output.

Enter the ascii value: 67

The character value of '67' is C

These are sample ASCII programs in c++. Hope, these programs make you familiar with ASCII concepts. Keep coding!!!!

Comments

Popular posts from this blog

How to create a XML DTD for displaying student details

How to write your first XML program?

Java NIO examples to illustrate channels and buffers.