Presentation is loading. Please wait.

Presentation is loading. Please wait.

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,

Similar presentations


Presentation on theme: "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,"— Presentation transcript:

1 Text Representation within Computers CS208

2 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

3 Binary Bit Strings 1 bit 0101 2 bits 00 01 10 11 3 bits 000 001 010 011 100 101 110 111 4 bits 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 Each additional bit doubles the number of possible combinations 2 4 16 8

4 The ASCII Code When you type text characters at your keyboard, each character is stored as a separate bit code. 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.

5 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…)

6 7-Bit ASCII Code Table RightmostLeftmost Three Bits Four Bits000001010011100101110111 0000NULDLESpace0@P`p 0001SOHDC1!1AQaq 0010STXDC2"2BRbr 0011ETXDC3#3CScs 0100EOTDC4$4DTdt 0101ENQNAK%5EUeu 0110ACKSYN&6FVfv 0111BELETB'7GWgw 1000BSCAN(8HXhx 1001HTEM)9IYiy 1010LFSUB*:JZjz 1011VTESC+;K[k{ 1100FFFS,<L\l| 1101CRGS-=M]m} 1110SORS.>N^n~ 1111SIUS/?O_oDEL

7 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

8 Finding ASCII values for Characters using the Table Example 1: Find the binary ASCII and decimal ASCII values for the ‘&’ character. RightmostLeftmost Three Bits Four Bits000001010011100101110111 0000NULDLESpace0@P`p 0001SOHDC1!1AQaq 0010STXDC2"2BRbr 0011ETXDC3#3CScs 0100EOTDC4$4DTdt 0101ENQNAK%5EUeu & 0110ACKSYN & 6FVfv 0111BELETB'7GWgw 1000BSCAN(8HXhx 1001HTEM)9IYiy 1010LFSUB*:JZjz 1011VTESC+;K[k{ 1100FFFS,<L\l| 1101CRGS-=M]m} 1110SORS.>N^n~ 1111SIUS/?O_oDEL

9 Finding ASCII values for Characters using the Table From the chart: ‘&’ = 0100110(binary ASCII value) Convert the binary value to decimal: 0100110 2 = 32 + 4 + 2 = 38 10 Therefore: ‘&’ = 38 10 (decimal ASCII value)

10 Finding ASCII values for Characters using the Table Example 2: Find the binary, octal, and hex ASCII values for the ‘M’ character. RightmostLeftmost Three Bits Four Bits000001010011100101110111 0000NULDLESpace0@P`p 0001SOHDC1!1AQaq 0010STXDC2"2BRbr 0011ETXDC3#3CScs 0100EOTDC4$4DTdt 0101ENQNAK%5EUeu 0110ACKSYN&6FVfv 0111BELETB'7GWgw 1000BSCAN(8HXhx 1001HTEM)9IYiy 1010LFSUB*:JZjz 1011VTESC+;K[k{ 1100FFFS,<L\l| 1101CRGS-=M]m} 1110SORS.>N^n~ 1111SIUS/?O_oDEL

11 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 101 2 = 115 8 (octal ASCII value) Convert the binary value to hexadecimal (by 4s): 0100 1101 2 = 4D 16 (hex ASCII value)

12 Finding Characters represented using the Table Example 3: What does the following binary ASCII code represent? 1001111 1001011

13 Finding Characters represented using the Table Example: Find 1001111 and 1001011 in the table RightmostLeftmost Three Bits Four Bits000001010011100101110111 0000NULDLESpace0@P`p 0001SOHDC1!1AQaq 0010STXDC2"2BRbr 0011ETXDC3#3CScs 0100EOTDC4$4DTdt 0101ENQNAK%5EUeu 0110ACKSYN&6FVfv 0111BELETB'7GWgw 1000BSCAN(8HXhx 1001HTEM)9IYiy 1010LFSUB*:JZjz 1011VTESC+;K[k{ 1100FFFS,<L\l| 1101CRGS-=M]m} 1110SORS.>N^n~ 1111SIUS/?O_oDEL

14 Finding Characters represented using the Table From the table: 1001111 = O 1001011 = K So 1001111 1001011 represents OK in binary ASCII

15 Character Representation ASCII Table Example 4: What character is represented by the decimal ASCII value 88 ? Convert the decimal value to binary: 88 10 = 64 + 16 + 8 = 1011000 2 (binary ASCII value) From the chart: 101 1000 = ‘X’ Therefore: 88 = ‘X’ (decimal ASCII value)

16 Decimal ASCII Example H i, H e a t h e r. 72 105 44 32 72 101 97 116 104 101 114 46

17 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? 1001000 2 1101001 2 How would you represent the SAME text in octal ASCII? (Answers on NEXT slide)

18 Answers So?=1010011 2 1101111 2 0111111 2 In decimal ASCII=83 10 111 10 63 10 1001000 2 1101001 2 represents text Hi The same text in octal ASCII is 110 8 151 8


Download ppt "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,"

Similar presentations


Ads by Google