What is ASCII Code: Definition and Examples
ASCII code is a system that assigns numbers to letters, digits, and symbols so computers can understand and display text. It uses numbers from 0 to 127 to represent common characters in English.How It Works
Think of ASCII code as a secret language that computers use to talk about letters and symbols. Each character you see on the screen, like the letter A or the number 5, has a special number assigned to it. For example, the letter A is number 65, and the number 5 is number 53.
This system works like a simple codebook. When you type a letter, the computer looks up its number in the ASCII table and stores or sends that number. When it needs to show the letter again, it reads the number and shows the matching character. This way, computers can share text easily and correctly.
ASCII only covers basic English letters, digits, and some symbols, using numbers from 0 to 127. This makes it simple and fast but limited to basic characters.
Example
This example shows how to convert a letter to its ASCII number and back using Python code.
letter = 'A' ascii_number = ord(letter) print(f"The ASCII code for '{letter}' is {ascii_number}") number = 66 character = chr(number) print(f"The character for ASCII code {number} is '{character}'")
When to Use
ASCII code is useful when you need to work with simple text data that uses English letters, digits, and common symbols. It is often used in programming, data files, and communication between devices where only basic characters are needed.
For example, early computers and many communication protocols use ASCII to send text messages. It is also helpful when you want to understand how text is stored inside a computer or when converting characters to numbers for sorting or encryption.
Key Points
- ASCII assigns numbers from 0 to 127 to letters, digits, and symbols.
- It is a simple way for computers to represent text.
- ASCII covers only basic English characters and some control codes.
- It is widely used in programming and data communication.