Code Skiller logoCB Logo
Logo LearnLearnLogo PracticePracticeLogo HireHireLogo IDEIDE

What is ASCII?

User image

Published by

sanya sanya

Published at: 21st May, 2023
5.14 mins read

What is ASCII?

The most used character encoding format for text data in computers and on the internet is ASCII (American Standard Code for Information Interchange). There are distinct values for 128 extra alphabetic, numeric, special, and control characters in ASCII-encoded data.

The character encoding used for telegraph data provides the foundation for ASCII encoding. In 1963, the American National Standards Institute released it as a computing standard for the first time.

Upper- and lowercase letters A through Z, numbers 0 through 9, and basic punctuation marks are all included in ASCII encoding. Additionally, it employs a few control characters that aren't used for printing but were developed for teletype printing terminals.

The following are possible representations for ASCII characters:

  • base-16 numerals, expressed as 0 through 9 and A through F for the decimal values of 10-15, as pairs of hexadecimal digits.
  • as octal (base 8) numerals with three digits;
  • as decimal values between 0 and 127;
  • 7-bit or 8-bit binary format.

For instance, the following examples show how the lowercase letter "m" is encoded in ASCII:

Character Hexadecimal Octal Decimal Binary (7 bit) Binary (8 bit)
m 0x6D /155 109 1101101 01101101

The most significant bit, which is often the left-most bit, was set to 0 for ASCII characters' initial 7-bit encoding and storage as 8-bit characters.

How does ASCII work?

For fundamental data exchanges, ASCII offers a character set that is widely used and understood. It lets programmers create user interfaces that both computers and people can understand. A string of data is encoded using ASCII as ASCII characters, which computers can read as data and display as legible plain text.

The ASCII character set's design is used by programmers to make some tasks simpler. For instance, altering a single bit in ASCII character codes makes it simple to change text from uppercase to lowercase.

The binary value represents the capital letter "A" as follows:

0100 0001

The binary value represents the lowercase letter "a" as follows:

0110 0001

The third most important difference is the difference itself. This is equivalent to: in decimal and hexadecimal form.

Character Binary Decimal Hexadecimal
A 0100 0001 65 0x41
a 0110 0001 97 0x61

The ASCII character code can be changed from uppercase to lowercase and back because the difference between upper- and lowercase characters is always 32 (0x20 in hexadecimal).

Similar to this, the hexadecimal representations of the numbers 0 through 9 are as follows:

Character Binary Decimal Hexadecimal
0 0011 0000 48 0x30
1 0011 0001 49 0x31
2 0011 0010 50 0x32
3 0011 0011 51 0x33
4 0011 0100 52 0x34
5 0011 0101 53 0x35
6 0011 0110 54 0x36
7 0011 0111 55 0x37
8 0011 1000 56 0x38
9 0011 1001 57 0x39

Developers can quickly translate ASCII digits to numerical values using this encoding by removing the four most important bits from the binary ASCII values (0011). Another way to calculate this is to remove the first hexadecimal digit or take 48 out of the decimal ASCII code.

Developers can also confirm that an ASCII value is present in a data stream, string, or file by looking at the character's most important bit. Basic ASCII characters always have a significant bit of 0, and if that bit is 1 then the character is not ASCII-encoded.

Example With a Code

Here is a brief Python code example that shows how to translate a string to its ASCII equivalent:

https://images.codingblocks.com/data-science/ASCII.png

In this code, we begin by creating a variable called string that holds the string that we want to encode as ASCII characters. Additionally, we declare the ASCII codes for each character in the string in an empty string called ascii_code.

Then, using a for loop to iterate through each character in the string, we convert each character to its matching ASCII code using the built-in Python function ord(). The Unicode code point of a character is returned as an integer by the ord() method.

Using the str() function, we turn the numeric value into a string and concatenate it with a space character to separate each ASCII code in the output string.

The ASCII codes for each character in the original string are then printed out in the ascii_code string. This code would provide the following results for the string "Hello, world!"

72 101 108 108 111 44 32 119 111 114 108 100 33

The Applications of ASCII Values

  • Text encoding: ASCII values offer a standardized way to represent text in computers and other electronic devices, simplifying the transfer and presentation of data between various platforms and systems.
  • Data transmission: Text-based data is encoded and transmitted between devices using ASCII values in communication protocols like the Internet Protocol (IP) and Simple Mail Transfer Protocol (SMTP).
  • Computer: To represent characters in strings, arrays, and other data types, computer languages frequently employ ASCII values.
  • File formats: Text data is often encoded using ASCII values in several file formats, including text and CSV files.
  • Keyboard input: When you type a character on your keyboard, your computer decodes that character into its matching ASCII value and displays that value on your screen.

Conclusion

ASCII values are crucial to computer operations and information transmission. ASCII values offer a uniform way to represent text in computers and other electronic devices by giving each character in the ASCII character set a different number code. This makes it possible to communicate and exchange data across many platforms and gadgets.

Library

WEB DEVELOPMENT

FAANG QUESTIONS

On this page

What is ASCII?

How does ASCII work?

Example With a Code

The Applications of ASCII Values

Conclusion