ASCII and Unicode: A Comprehensive Guide šŸ“

beginner
21 min

ASCII and Unicode: A Comprehensive Guide šŸ“

Welcome to our deep dive into the world of ASCII and Unicode! Today, we'll explore these fascinating systems that help us communicate with computers. šŸŽÆ

What is ASCII? šŸ’”

ASCII (American Standard Code for Information Interchange) is a character encoding standard used in computing to represent alphabets, numbers, and symbols. It was developed in the 1960s and contains 128 unique characters.

Here's an ASCII table snippet for your reference:

0 1 2 3 4 5 6 7 8 9 A B C D E F 0 NUL SOH STX ETX EOT ENQ ACK BEL BS FS GS RS US SP ! " # $ % & ' ( ) * + , - . / 1 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _ ` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~ DEL

šŸ“ Note: NUL, SOH, STX, ETX, EOT, ENQ, ACK, BEL, BS, FS, GS, RS, US, and DEL are special characters in ASCII with specific functions.

What is Unicode? šŸ’”

Unicode is a more extensive character encoding system that supports a vast range of scripts and languages, including ASCII. Unicode can represent more than 130,000 characters from virtually every written language.

Unicode hex code range: U+0000 - U+10FFFF

šŸ“ Note: The Unicode standard assigns a unique hexadecimal number (Unicode code point) to each character.

ASCII vs Unicode šŸ’”

  • ASCII has only 128 characters, whereas Unicode supports more than 130,000 characters.
  • ASCII is limited to Western European languages, while Unicode can represent scripts from every part of the world.
  • ASCII characters are encoded as 7-bit bytes, while Unicode uses 21-bit UTF-8 encoding or 32-bit UTF-16 encoding.

ASCII and Unicode in Programming šŸ’”

In programming, we often use libraries and functions to work with ASCII and Unicode characters.

Example 1: Printing ASCII characters in Python āœ…

python
# Print ASCII characters in Python for i in range(ord('@'), ord('~')+1): print(chr(i), end=" ")

Example 2: Printing Unicode characters in Python āœ…

python
# Print Unicode characters in Python for i in range(9728, 12288): # Emoji range in Unicode print(chr(i), end=" ")

šŸ“ Note: The examples above use the ord() function to get the ASCII value of a character and the chr() function to get the character from its ASCII value.

Quiz šŸ’”

Quick Quiz
Question 1 of 1

What is the total number of unique characters in ASCII?

That's it for today! We hope you enjoyed learning about ASCII and Unicode. Stay tuned for more exciting lessons on Data Structures and Algorithms. Happy coding! šŸ˜„šŸ’»šŸš€