Open In App

Program to implement ASCII lookup table

Last Updated : 08 Feb, 2024
Comments
Improve
Suggest changes
1 Like
Like
Report

ASCII stands for American Standard Code for Information Interchange. Computers can only understand numbers, so an ASCII code is the numerical representation of a character such as ‘a’ or ‘@’ or an action of some sort. ASCII lookup table is a tabular representation of corresponding values associated to a character i.e. we can lookup the corresponding octal, decimal, hexadecimal or HTML ASCII of a character. 

Here, we are implementing an ASCII lookup table which takes a character as an input and returns the equivalent octal, decimal, hexadecimal and HTML ASCII value for the character. This ASCII lookup table works for alphabets, digits, operators, separators and special symbols. 

Example:

Input character = @ 
Output :
Octal value: 100
Decimal value: 64
Hexadecimal value: 40
HTML value: @
  • Step 1: Convert given character into it's equivalent ASCII in decimal form. This can be done by implicitly typecasting the character into an integral value(or subtracting by null). 
  • Step 2: The value computed in step 1 becomes the decimal representation of the character. Convert the decimal value in octal and hexadecimal forms to obtain the ASCII of the input character into the given formats.
  • Step 3: Add characters &# as prefix and ; as postfix of the decimal ASCII, the expression obtained becomes the HTML ASCII of the given character. This way we can easily implement the ASCII lookup table. Follow the code below to see the implementation. 

Implementation:

C++
Java Python3 C# JavaScript

Output
Octal value: 100
Decimal value: 64
Hexadecimal value: 40
HTML value: @

Time Complexity: O(log8(Decimal)), as we are using a loop and in each traversal we are decrementing N by floor division of 8.
Auxiliary Space: O(log8(Decimal)), as we are using extra space for the answer.


Article Tags :
Practice Tags :

Similar Reads