180 likes | 314 Views
Text Representation within Computers. CS208. The Binary Digit (Bit). One bit can encode a value set that contains two elements e.g. {black, white}, {up, down}, {registered, not registered}, etc. What if we need to encode a value set that contains three values?
E N D
The Binary Digit (Bit) • One bit can encode a value set that contains two elements • e.g. {black, white}, {up, down}, {registered, not registered}, etc. • What if we need to encode a value set that contains three values? • e.g. {red, yellow, green} for a traffic signal • Can use a string of two bits: 00 = red 01 = yellow 11 = green
1 bit 2 bits 3 bits 4 bits 0 1 00 01 10 11 000 001 010 011 100 101 110 111 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 Binary Bit Strings 2 4 8 16 Each additional bit doubles the number of possible combinations
The ASCII Code • When you type text characters at your keyboard, each character is stored as a separate bitcode. • A standard bit code was assigned to each possible character that can appear in text. • The code is called the ASCII (American Standard Code for Information Interchange) code.
The ASCII Code • Original ASCII was a 7–bit code • ANSI identified a standard set of 128 characters (including letters, digits, symbols and special control characters) • 7 bits can provide 128 distinct bit patterns (codes) • Extended ASCII is an 8-bit code • Additional 128 codes are used to accommodate letters from other languages (Arabic, French, German, etc…)
7-Bit ASCII Code Table Rightmost Leftmost Three Bits Four Bits 000001010011100101110111 0000 NUL DLE Space 0 @ P ` p 0001 SOH DC1 ! 1 A Q a q 0010 STX DC2 " 2 B R b r 0011 ETX DC3 # 3 C S c s 0100 EOT DC4 $ 4 D T d t 0101 ENQ NAK % 5 E U e u 0110 ACK SYN & 6 F V f v 0111 BEL ETB ' 7 G W g w 1000 BS CAN ( 8 H X h x 1001 HT EM ) 9 I Y i y 1010 LF SUB * : J Z j z 1011 VT ESC + ; K [ k { 1100 FF FS , < L \ l | 1101 CR GS - = M ] m } 1110 SO RS . > N ^ n ~ 1111 SI US / ? O _ o DEL
Using the ASCII Code Table • Find a character in the chart • Use the 3 bits at the top of the column the character is in, as the first 3 bits • Use the 4 bits in at the far left side of the row that the character is in, as the last 4 bits • This creates a binary 7-bit ASCII code • NOTE: a leading zero is added when the code is stored in one byte
Finding ASCII values for Characters using the Table Example 1:Find the binary ASCII and decimal ASCII values for the ‘&’ character. Rightmost Leftmost Three Bits Four Bits000001010011100101110111 0000 NUL DLE Space 0 @ P ` p 0001 SOH DC1 ! 1 A Q a q 0010 STX DC2 " 2 B R b r 0011 ETX DC3 # 3 C S c s 0100 EOT DC4 $ 4 D T d t 0101 ENQ NAK % 5 E U e u 0110 ACK SYN & 6 F V f v 0111 BEL ETB ' 7 G W g w 1000 BS CAN ( 8 H X h x 1001 HT EM ) 9 I Y i y 1010 LF SUB * : J Z j z 1011 VT ESC + ; K [ k { 1100 FF FS , < L \ l | 1101 CR GS - = M ] m } 1110 SO RS . > N ^ n ~ 1111 SI US / ? O _ o DEL
Finding ASCII values for Characters using the Table From the chart: ‘&’ = 0100110 (binary ASCII value) Convert the binary value to decimal: 01001102 = 32 + 4 + 2 = 3810 Therefore: ‘&’ = 3810 (decimal ASCII value)
Finding ASCII values for Characters using the Table Example 2:Find the binary , octal, and hex ASCII values for the ‘M’ character. Rightmost Leftmost Three Bits Four Bits000001010 011100101110111 0000 NUL DLE Space 0 @ P ` p 0001 SOH DC1 ! 1 A Q a q 0010 STX DC2 " 2 B R b r 0011 ETX DC3 # 3 C S c s 0100 EOT DC4 $ 4 D T d t 0101 ENQ NAK % 5 E U e u 0110 ACK SYN & 6 F V f v 0111 BEL ETB ' 7 G W g w 1000 BS CAN ( 8 H X h x 1001 HT EM ) 9 I Y i y 1010 LF SUB * : J Z j z 1011 VT ESC + ; K [ k { 1100 FF FS , < L \ l | 1101 CR GS - = M ] m } 1110 SO RS . > N ^ n ~ 1111 SI US / ? O _ o DEL
Finding ASCII values for Characters using the Table From the chart: ‘M’ = 1001101 (binary ASCII value) Convert the binary value to octal (re-group by 3s): 001 001 1012 = 1158(octal ASCII value) Convert the binary value to hexadecimal (by 4s): 0100 11012 = 4D16 (hex ASCII value)
Finding Characters represented using the Table Example 3: What does the following binary ASCII code represent? 1001111 1001011
Finding Characters represented using the Table Example:Find 1001111 and 1001011 in the table Rightmost Leftmost Three Bits Four Bits000001010 011100101110111 0000 NUL DLE Space 0 @ P ` p 0001 SOH DC1 ! 1 A Q a q 0010 STX DC2 " 2 B R b r 0011 ETX DC3 # 3 C S c s 0100 EOT DC4 $ 4 D T d t 0101 ENQ NAK % 5 E U e u 0110 ACK SYN & 6 F V f v 0111 BEL ETB ' 7 G W g w 1000 BS CAN ( 8 H X h x 1001 HT EM ) 9 I Y i y 1010 LF SUB * : J Z j z 1011 VT ESC + ; K [ k { 1100 FF FS , < L \ l | 1101 CR GS - = M ] m } 1110 SO RS . > N ^ n ~ 1111 SI US / ? O _ o DEL
Finding Characters represented using the Table From the table: 1001111 = O 1001011 = K So 1001111 1001011 represents OK in binary ASCII
Character Representation ASCII Table Example 4: What character is represented by the decimal ASCII value 88? Convert the decimal value to binary: 8810 = 64 + 16 + 8 = 10110002 (binary ASCII value) From the chart: 101 1000 = ‘X’ Therefore: 88 = ‘X’ (decimal ASCII value)
Decimal ASCII Example H i , H e a t h e r . 72 105 44 32 72 101 97 116 104 101 114 46
Try It Yourself –Text Representation • How would the text So? be represented in binary ASCII? • How would the SAME text be represented in decimal ASCII? • What text does the following binary ASCII represent? 10010002 11010012 • How would you represent the SAME text in octal ASCII? (Answers on NEXT slide)
Answers • So? = 10100112 11011112 01111112 • In decimal ASCII = 8310 11110 6310 • 10010002 11010012 represents text Hi • The same text in octal ASCII is 1108 1518