Character Encoding: ASCII and Unicode
How computers store letters, numbers and symbols internally as binary codes.
Character Encoding: ASCII and Unicode
Character Encoding का अर्थ है characters (अक्षरों), numbers (संख्याओं) और symbols (चिह्नों) को ऐसे numeric codes में represent करना जिन्हें computer समझ और store कर सके। Computer internally data को binary form यानी 0 और 1 के रूप में process करता है। इसलिए प्रत्येक character को एक unique code दिया जाता है।
What is Character Encoding?
Computer सीधे human-readable characters जैसे A, B, a, 1, @, हिंदी आदि को उसी रूप में process नहीं करता। Character encoding system प्रत्येक character को एक numeric value प्रदान करता है और computer उस value को binary form में store और process करता है।
उदाहरण के लिए, ASCII encoding में capital letter A का decimal code 65 होता है। Computer इसे binary form में represent कर सकता है।
A → 65 (Decimal) → 01000001 (Binary)
Need for Character Encoding
Character encoding की आवश्यकता इसलिए होती है क्योंकि computers को text को numerical form में store, process और transmit करना होता है। Encoding के बिना अलग-अलग computer systems के बीच text को सही तरीके से represent और exchange करना कठिन हो सकता है।
Character encoding का उपयोग text files, web pages, databases, emails, programming languages और अन्य digital systems में किया जाता है।
ASCII
ASCII का पूरा नाम American Standard Code for Information Interchange है। यह एक widely used character encoding standard है जिसका उपयोग letters, digits, punctuation marks और कुछ control characters को represent करने के लिए किया जाता है।
Standard ASCII में प्रत्येक character को 7 bits में represent किया जाता है। इसलिए ASCII में कुल 128 characters को represent किया जा सकता है।
7 bits → 27 = 128 characters
ASCII Character Set
ASCII में English alphabet, digits, punctuation marks और control characters शामिल होते हैं।
| Character | Decimal Code | Binary Representation |
|---|---|---|
| A | 65 | 1000001 |
| B | 66 | 1000010 |
| a | 97 | 1100001 |
| b | 98 | 1100010 |
| 0 | 48 | 0110000 |
| 1 | 49 | 0110001 |
| Space | 32 | 0100000 |
ASCII Example
यदि character A को ASCII में represent करना है, तो उसका decimal value 65 होता है। 65 का binary representation 1000001 है। 8-bit storage representation में इसे 01000001 लिखा जा सकता है।
ASCII Control Characters
ASCII में केवल printable characters ही नहीं बल्कि कुछ control characters भी होते हैं। इनका उपयोग text formatting और communication-related operations के लिए किया जाता है।
| Character/Name | ASCII Decimal Code | Purpose |
|---|---|---|
| NUL | 0 | Null character |
| TAB | 9 | Horizontal tab |
| LF | 10 | Line Feed |
| CR | 13 | Carriage Return |
| Space | 32 | Blank space |
Limitations of ASCII
ASCII की सबसे बड़ी limitation यह है कि standard ASCII केवल 128 characters को represent कर सकता है। इसमें मुख्य रूप से English characters और limited symbols शामिल हैं।
इसलिए Hindi, Chinese, Japanese, Arabic और अन्य अनेक languages के characters को standard ASCII में directly represent नहीं किया जा सकता।
- Standard ASCII में केवल 128 characters होते हैं।
- यह मुख्य रूप से English language के लिए बनाया गया था।
- इसमें अनेक international languages के characters उपलब्ध नहीं हैं।
- Modern multilingual computing के लिए ASCII अकेला पर्याप्त नहीं है।
Extended ASCII
Extended ASCII शब्द का उपयोग ऐसे 8-bit character sets के लिए किया जाता है जिनमें 256 possible values हो सकती हैं। इनमें standard ASCII के 128 characters के अतिरिक्त अन्य characters और symbols शामिल किए जा सकते हैं।
हालाँकि, extended ASCII का कोई एक universal character set नहीं है। अलग-अलग systems ने अलग-अलग 8-bit encodings का उपयोग किया है। इसलिए यह Unicode की तरह एक single universal character encoding standard नहीं है।
Unicode
Unicode एक universal character encoding standard है जिसे दुनिया की विभिन्न languages के characters को एक common system में represent करने के लिए विकसित किया गया है।
Unicode में English के साथ-साथ Hindi, Sanskrit, Bengali, Tamil, Chinese, Japanese, Arabic और अन्य अनेक languages के characters को represent किया जा सकता है। इसके अलावा mathematical symbols, currency symbols, technical symbols और emoji जैसे characters भी Unicode में शामिल हैं।
Why Unicode is Important?
Internet और modern software applications में users अलग-अलग languages में text लिखते हैं। Unicode के कारण एक ही digital system में विभिन्न languages के text को reliably represent और exchange किया जा सकता है।
उदाहरण के लिए, निम्न characters अलग-अलग scripts से हैं लेकिन Unicode system में represent किए जा सकते हैं:
Unicode and Indian Languages
Unicode Indian languages के characters को digital systems में represent करने के लिए बहुत महत्वपूर्ण है। Hindi सहित Devanagari script के characters Unicode में defined हैं।
इसका अर्थ है कि Hindi text को computers, websites, smartphones और databases में standard तरीके से store और exchange किया जा सकता है।
Example:
Unicode Encoding Forms
Unicode characters को store और transmit करने के लिए विभिन्न encoding forms का उपयोग किया जाता है। इनमें प्रमुख हैं:
- UTF-8
- UTF-16
- UTF-32
UTF-8
UTF-8 का पूरा नाम Unicode Transformation Format - 8-bit है। यह Unicode को encode करने का एक widely used format है। इसमें characters को 1 से 4 bytes में represent किया जा सकता है।
ASCII के standard characters UTF-8 में उसी byte values के साथ compatible रहते हैं। यही कारण है कि UTF-8 web pages और internet पर बहुत widely used है।
UTF-16
UTF-16 Unicode characters को सामान्यतः 16-bit code units के माध्यम से represent करता है। कुछ characters को represent करने के लिए दो 16-bit code units की आवश्यकता हो सकती है।
UTF-32
UTF-32 प्रत्येक Unicode code point को fixed 32-bit unit में represent करता है। इसकी representation सरल होती है, लेकिन memory usage UTF-8 की तुलना में अधिक हो सकता है।
| Encoding | Basic Unit | Important Feature |
|---|---|---|
| UTF-8 | 8-bit units | 1 से 4 bytes तक उपयोग कर सकता है |
| UTF-16 | 16-bit units | Characters को 1 या 2 code units में represent कर सकता है |
| UTF-32 | 32-bit units | प्रत्येक code point के लिए fixed 32-bit representation |
ASCII vs Unicode
| ASCII | Unicode |
|---|---|
| American Standard Code for Information Interchange | Universal character standard |
| Standard ASCII 7 bits का उपयोग करता है | Unicode को UTF-8, UTF-16, UTF-32 जैसे formats में encode किया जा सकता है |
| 128 standard characters represent करता है | बहुत बड़ी संख्या में characters और symbols represent कर सकता है |
| मुख्य रूप से English characters के लिए बनाया गया था | अनेक languages और scripts को support करता है |
| Modern multilingual applications के लिए limited है | Modern multilingual computing के लिए suitable है |
ASCII and Unicode in C++
C++ programs में characters को character literals के रूप में लिखा जा सकता है। Character literal को single quotes में लिखा जाता है।
#include <iostream>
using namespace std;
int main()
{
char ch = 'A';
cout << ch << endl;
cout << static_cast<int>(ch);
return 0;
}
A
65
ऊपर के example में 'A' character को int में convert करने पर ASCII value 65 प्राप्त होती है।
Character Encoding in Text Files
जब कोई text file बनाई जाती है, तो characters को किसी encoding के अनुसार bytes में store किया जाता है। यदि file को सही encoding के साथ read किया जाए, तो original text correctly दिखाई देता है।
उदाहरण के लिए, Hindi text वाली file को UTF-8 encoding में save करने पर Hindi characters को सही तरीके से store और display किया जा सकता है।
Encoding and Decoding
Encoding का अर्थ characters को किसी specified encoding scheme के अनुसार bytes या numeric representation में बदलना है।
Decoding का अर्थ encoded data को वापस readable characters में convert करना है।
Decoding: Code/Bytes → Character
Example of Encoding and Decoding
मान लीजिए किसी system में English character A को ASCII के अनुसार encode किया गया है। इसका decimal code 65 है और binary representation 01000001 हो सकता है। जब system इस encoded value को सही तरीके से decode करता है, तो उसे फिर से A character के रूप में display किया जा सकता है।
| Stage | Representation |
|---|---|
| Original Character | A |
| ASCII Decimal Code | 65 |
| Binary Representation | 01000001 |
| Decoded Character | A |
Character Encoding and Programming
Programming में character encoding का महत्व इसलिए है क्योंकि programs में text, strings और character data का उपयोग बहुत अधिक होता है। Source code files, input/output, databases और web applications में सही encoding का उपयोग आवश्यक है।
Modern programming environments में Unicode support के कारण programmers विभिन्न languages के text के साथ काम कर सकते हैं।
Important Points
- Character encoding characters को numeric codes में represent करने की method है।
- Computer internally data को binary form में process करता है।
- ASCII का पूरा नाम American Standard Code for Information Interchange है।
- Standard ASCII 7 bits का उपयोग करता है।
- Standard ASCII में 128 characters होते हैं।
- ASCII मुख्य रूप से English characters और basic symbols के लिए बनाया गया था।
- Unicode विभिन्न languages और scripts के characters को represent कर सकता है।
- UTF-8, UTF-16 और UTF-32 Unicode encoding forms हैं।
- UTF-8 1 से 4 bytes का उपयोग कर सकता है।
- Encoding characters को coded representation में बदलती है।
- Decoding coded representation को वापस characters में बदलती है।
Board Focus
ASCII → American Standard Code for Information Interchange
Standard ASCII → 7 bits → 128 characters
Unicode → Universal character standard
UTF-8 → 1 से 4 bytes
UTF-16 → 16-bit code units
UTF-32 → 32-bit representation
Encoding → Character को coded representation में बदलना
Decoding → Coded representation को character में बदलना
Board Important Questions
Very Short Answer Questions
Q1. Character Encoding क्या है?
Answer: Character Encoding वह method है जिसमें characters को computer द्वारा process और store करने के लिए numeric codes या bytes में represent किया जाता है।
Q2. ASCII का पूरा नाम क्या है?
Answer: American Standard Code for Information Interchange.
Q3. Standard ASCII कितने bits का उपयोग करता है?
Answer: 7 bits.
Q4. Standard ASCII में कितने characters होते हैं?
Answer: 128 characters.
Q5. Unicode क्या है?
Answer: Unicode एक universal character standard है जो विभिन्न languages और symbols के characters को represent करने के लिए उपयोग किया जाता है।
Q6. UTF-8 क्या है?
Answer: UTF-8 Unicode का एक widely used encoding format है जो characters को 1 से 4 bytes में encode कर सकता है।
Q7. ASCII में 'A' का decimal code क्या है?
Answer: 65.
Q8. Encoding और Decoding क्या हैं?
Answer: Encoding characters को coded representation में बदलना और Decoding coded representation को वापस characters में बदलना है।
Short Answer Questions
Q9. ASCII क्या है? इसकी मुख्य विशेषताएँ लिखिए।
Answer: ASCII का पूरा नाम American Standard Code for Information Interchange है। Standard ASCII 7 bits का उपयोग करता है और कुल 128 characters को represent कर सकता है। इसमें English letters, digits, punctuation marks और control characters शामिल हैं।
Q10. Unicode की आवश्यकता क्यों पड़ी?
Answer: ASCII मुख्य रूप से English characters के लिए पर्याप्त था और standard ASCII केवल 128 characters represent कर सकता था। विभिन्न languages के characters को represent करने के लिए एक universal standard की आवश्यकता थी। इसी आवश्यकता को पूरा करने के लिए Unicode का उपयोग किया जाता है।
Q11. ASCII और Unicode में अंतर बताइए।
| ASCII | Unicode |
|---|---|
| Standard ASCII 7 bits का उपयोग करता है। | Unicode को विभिन्न encoding formats में represent किया जाता है। |
| 128 standard characters represent करता है। | बहुत बड़ी संख्या में characters represent कर सकता है। |
| मुख्य रूप से English characters के लिए बनाया गया था। | अनेक languages और scripts को support करता है। |
Q12. UTF-8, UTF-16 और UTF-32 क्या हैं?
Answer: UTF-8, UTF-16 और UTF-32 Unicode के encoding forms हैं। UTF-8 characters को 1 से 4 bytes में encode कर सकता है। UTF-16 16-bit code units का उपयोग करता है और UTF-32 Unicode code points को fixed 32-bit units में represent करता है।
Long Answer Questions
Q13. Character Encoding को उदाहरण सहित समझाइए।
Answer: Character Encoding एक ऐसी method है जिसके द्वारा characters को numeric codes या bytes में represent किया जाता है ताकि computer उन्हें store, process और transmit कर सके। उदाहरण के लिए ASCII encoding में character 'A' का decimal code 65 होता है। इसका binary representation 01000001 हो सकता है। Computer इसी coded representation के आधार पर character को process करता है।
Q14. ASCII और Unicode की तुलना कीजिए।
Answer: ASCII एक character encoding standard है जो मुख्य रूप से English letters, digits, punctuation marks और control characters को represent करने के लिए बनाया गया था। Standard ASCII 7 bits का उपयोग करता है और 128 characters represent कर सकता है। Unicode एक universal character standard है जो दुनिया की विभिन्न languages और scripts के characters को represent करने के लिए बनाया गया है। Unicode को UTF-8, UTF-16 और UTF-32 जैसे encoding formats में encode किया जा सकता है।
Q15. Encoding और Decoding को उदाहरण सहित समझाइए।
Answer: Encoding में readable character को coded representation में बदला जाता है, जबकि decoding में coded representation को वापस readable character में बदला जाता है। उदाहरण के लिए ASCII में 'A' का decimal code 65 है। 'A' को 65 के रूप में represent करना encoding का उदाहरण है और 65 को वापस 'A' के रूप में interpret करना decoding का उदाहरण है।
Quick Revision
- Character Encoding: Characters को codes/bytes में represent करना
- ASCII: American Standard Code for Information Interchange
- Standard ASCII: 7 bits और 128 characters
- Unicode: विभिन्न languages के characters के लिए universal standard
- UTF-8: Unicode encoding, 1–4 bytes
- UTF-16: 16-bit code units
- UTF-32: Fixed 32-bit representation
- Encoding: Character → Code/Bytes
- Decoding: Code/Bytes → Character
Practice Questions
- Character Encoding से आप क्या समझते हैं?
- ASCII का पूरा नाम लिखिए।
- Standard ASCII में कितने characters होते हैं?
- ASCII कितने bits का उपयोग करता है?
- Unicode क्या है?
- ASCII की limitations लिखिए।
- Unicode की आवश्यकता क्यों है?
- UTF-8, UTF-16 और UTF-32 को समझाइए।
- Encoding और Decoding में अंतर बताइए।
- ASCII और Unicode में अंतर स्पष्ट कीजिए।
- ASCII में character 'A' का decimal code क्या है?
- Computer में character encoding की क्या आवश्यकता है?