ASCII CODES
What is ASCII?
ASCII stands for American Standard Code for Information Interchange. It is a character encoding
standard that assigns a unique numeric value to letters, digits, punctuation marks, and control
characters. It was developed in the early 1960s and became the foundation of text-based data in
computing.
Structure of ASCII
ASCII uses 7 bits to represent each character, allowing for 128 different values (0 to 127). Extended
ASCII uses 8 bits (0 to 255) to support additional characters and symbols.
Categories of ASCII Characters:
- Control Characters (0-31 and 127): Non-printable characters used to control hardware (e.g.,
carriage return, line feed, tab).
- Printable Characters (32-126):
- Digits (48-57): '0' to '9'
- Uppercase letters (65-90): 'A' to 'Z'
- Lowercase letters (97-122): 'a' to 'z'
- Punctuation and symbols (33-47, 58-64, etc.)
Examples:
Character | ASCII Code (Decimal) | Binary
A | 65 | 01000001
a | 97 | 01100001
0 | 48 | 00110000
Space | 32 | 00100000
Uses of ASCII:
- Storing text in files (.txt, .html)
- Data communication between systems
- Programming (e.g., checking character values)
- Keyboard input mapping
Limitations:
- Only supports English characters and basic symbols
- Not suitable for international languages (solved by Unicode)
GRAY CODES
What is Gray Code?
Gray code, also known as reflected binary code, is a binary numeral system where two successive
values differ in only one bit. This minimizes errors in digital systems, especially in mechanical
encoders and communication systems.
Why Use Gray Code?
In binary systems, switching from one value to another might involve several bit changes, which can
lead to temporary false values. Gray code avoids this problem by changing only one bit at a time.
Gray Code Example (3-bit):
Decimal | Binary | Gray Code
0 | 000 | 000
1 | 001 | 001
2 | 010 | 011
3 | 011 | 010
4 | 100 | 110
5 | 101 | 111
6 | 110 | 101
7 | 111 | 100
How to Convert Binary to Gray Code:
1. The first bit remains the same.
2. Each following bit is obtained by XORing the previous binary bit with the current one.
Example: Binary 1011 -> Gray Code
- First bit: 1
- Second: 1 XOR 0 = 1
- Third: 0 XOR 1 = 1
- Fourth: 1 XOR 1 = 0
- Result: 1110
Applications of Gray Code:
- Rotary encoders (to measure angle/position)
- Digital-to-analog conversion
- Error correction in digital communication
- Karnaugh Maps (logic simplification)
Key Differences: ASCII vs Gray Code
Feature | ASCII | Gray Code
Purpose | Text representation | Error minimization in transitions
Bit Length | Typically 7 or 8 bits| Varies (based on system)
Characters | Represents symbols | Represents numbers
Use Case | Programming, text | Digital circuits, robotics