~ by RAKA on 01-August-2023
~ by RAKA on 01-August-2023
In the world of programming, computers aren't as "smart" as we often think. They only understand one language—binary (1s and 0s). Every complex task that we make them perform relies on logic, not magic. This is where programming languages like C come into play, helping us bridge the gap between human logic and computer language.
1. What is ASCII?
ASCII, which stands for American Standard Code for Information Interchange, is a character encoding standard used in computers and other electronic devices to represent text. It converts human-readable characters (like letters, numbers, and symbols) into binary, which the computer understands.
2. Why Do Computers Need ASCII?
Computers only understand binary—0 and 1. All information, whether it's numbers, letters, or symbols, is represented as a series of bits (binary digits). Each bit can either be 0 or 1. The combination of these bits forms what we call bytes.
• 1 bit can represent 21 = 2 values (0, 1).
• 2 bits can represent 22 = 4 values.
• 8 bits (1 byte) can represent 28 = 256 values (0-255).
This means that each character or symbol is associated with a unique number between 0 and 255 in ASCII.
3. How ASCII Represents Characters
The ASCII table assigns specific numbers to characters. For example:
• Digits 0 to 9 are represented by ASCII values from 48 to 57.
• Uppercase letters (A to Z) are represented by values from 65 to 90.
• Lowercase letters (a to z) are represented by values from 97 to 122.
Each of these characters is stored in memory as binary.
4. How Memory Works in Computers
Memory in computers is nothing but billions of tiny transistors, which can either be in a charged (0) or uncharged (1) state. These states are combined to form binary numbers, which computers then use to perform calculations, process data, and store information.
• 0101 1100 represents a byte.
• 1024 bytes make 1 KB (kilobyte).
• 1024 KB make 1 MB (megabyte), and so on.
Everything in memory, including characters, numbers, and commands, is stored as sequences of 0s and 1s. The beauty of ASCII is that it simplifies this process, allowing us to map human-readable characters into the language of the computer.
5. A Simple Task: Getting the ASCII Value of a Character
Let’s get hands-on with a small C program to find the ASCII value of any character. This is a basic task in C that helps us understand how characters are handled in programming.
1. Include the necessary header file
2. Create a main() function.
3. Take a character input from the user.
4. Print the ASCII value of that character.
Here’s the code to accomplish this:
#include <stdio.h>
void main() {
char ch;
// Step 1: Ask the user to input a character
printf("Please Enter Any character and press enter: ");
scanf("%c", &ch); // Taking user input
// Step 2: Display the ASCII value of the character
printf("ASCII value of character %c is %d", ch, ch);
}
How This Works:
• The user inputs a character, which is stored in the variable ch.
• The scanf() function reads the character entered by the user.
• The printf() function displays the character alongside its ASCII value using the format specifiers %c (for the character) and %d (for the ASCII value).
Now, whenever you want to check the ASCII value of a character, this simple C code can come in handy!
6. Why is ASCII Still Important?
Although newer encoding systems like Unicode have emerged to support a wider range of characters and symbols, ASCII remains foundational for understanding how computers process text. It’s the bedrock of most programming languages, including C, and understanding ASCII will help you build a strong programming foundation.
7. Conclusion
Understanding ASCII is essential for anyone learning programming, especially in C. It bridges the gap between how humans communicate and how computers process information. While computers might seem complex, ASCII simplifies the relationship between characters and binary data, allowing us to harness the power of computers more effectively.
So, whenever you type a letter on your keyboard, remember, it's more than just a letter—it’s a series of 0s and 1s that make everything possible!