Difference between revisions of "ASCII"
(→Overview) |
|||
(26 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
+ | ==Overview== | ||
+ | ===CraigNDave=== | ||
+ | <youtube>https://www.youtube.com/watch?v=Eex82ogB8n8&index=1&list=PLCiOXwirraUBIKvhutnNnMkVTpQ_psPN2</youtube> | ||
+ | |||
+ | https://www.youtube.com/watch?v=Eex82ogB8n8&index=1&list=PLCiOXwirraUBIKvhutnNnMkVTpQ_psPN2 | ||
+ | |||
+ | ===Computer Science Tutor=== | ||
+ | <youtube>tdmeXcDX-Uc</youtube> | ||
+ | |||
+ | https://www.youtube.com/watch?v=tdmeXcDX-Uc&list=PL04uZ7242_M6O_6ITD6ncf7EonVHyBeCm&index=6 | ||
+ | |||
==Definition== | ==Definition== | ||
− | ASCII stands for American Standard Code for Information Interchange. It is a character system that lets computers and devices to process letters, numbers and characters. It is represented by a 7-bit binary number that is either 0's or 1's. HTML (HyperText Markup Language) are based on ASCII. There are 128 characters that can be represented using ASCII. | + | ASCII stands for American Standard Code for Information Interchange. It is a character system that lets computers and devices to process letters, numbers and characters. It is represented by a 7-bit binary number that is either 0's or 1's. HTML (HyperText Markup Language) are based on ASCII (American Standard Code for Information Interchange). There are 128 characters that can be represented using ASCII. |
Below is a table showing all of the characters that can be represented using ASCII | Below is a table showing all of the characters that can be represented using ASCII | ||
+ | |||
+ | If you want to shift between the upper and lower case version of a character, you can add/minus 32 to the denary equivalent. | ||
+ | E.g to change ''A'' to ''a'', you would add 32 to 65, which would result in 97, and vice versa. | ||
+ | |||
+ | ''All of the ASCII codes can be found [[http://www.asciitable.com/ here]].'' | ||
[[File:ASCII.jpg]] | [[File:ASCII.jpg]] | ||
Line 8: | Line 24: | ||
==Extended ASCII== | ==Extended ASCII== | ||
This used an additional bit (ie 8 bits) to allow for additional characters. Overall extended ASCII supports the original ASCII values but adds the following: | This used an additional bit (ie 8 bits) to allow for additional characters. Overall extended ASCII supports the original ASCII values but adds the following: | ||
+ | |||
[[File:Extended ASCII.gif]] | [[File:Extended ASCII.gif]] | ||
Line 14: | Line 31: | ||
The 16-bit code can represent 65536 different characters. | The 16-bit code can represent 65536 different characters. | ||
+ | |||
+ | Unicode also added emoji compatibility, so now all emojis can be used as a unicode character. There are currently 2623 emojis contained within Unicode. | ||
It maintains compatibility with ASCII by using the same code values as ASCII (ie codes 0-255 are the same as the ASCII table). So if you take ‘z’ and its ASCII value 122 (0111 1010 in binary), the unicode value is still 122 the binary will be 0000 0000 0111 1010. | It maintains compatibility with ASCII by using the same code values as ASCII (ie codes 0-255 are the same as the ASCII table). So if you take ‘z’ and its ASCII value 122 (0111 1010 in binary), the unicode value is still 122 the binary will be 0000 0000 0111 1010. | ||
+ | |||
+ | ''All of the Unicode characters can be found [[http://www.unicode.org/charts/ here]].'' | ||
+ | |||
+ | [[File:Unicode Table.jpg]] | ||
=Trivia= | =Trivia= | ||
− | In many programming languages there are | + | In many programming languages there are methods built in which are able to convert integers to ASCII characters and vice versa. Below are examples for Lua and C#. (Note: C# actually converts to Unicode, but from characters 0-255 this is identical to ASCII.) |
+ | ==Lua== | ||
<syntaxhighlight lang="lua" line='line'> | <syntaxhighlight lang="lua" line='line'> | ||
local function convertToASCII(str) | local function convertToASCII(str) | ||
Line 31: | Line 55: | ||
print(convertToASCII("s")) -- > 115 | print(convertToASCII("s")) -- > 115 | ||
print(convertFromASCII(115)) -- > s | print(convertFromASCII(115)) -- > s | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | ==C#== | ||
+ | <syntaxhighlight lang="csharp" line='line'> | ||
+ | // Code to convert from an integer to an ASCII character. | ||
+ | int input = 65; | ||
+ | char output = Convert.ToChar(input); | ||
+ | Console.WriteLine("The integer " + input + " converts to the ASCII character " + output); | ||
+ | |||
+ | // Code to convert from an ASCII character to an integer. | ||
+ | char input1 = Convert.ToChar("A"); | ||
+ | int output1 = Convert.ToInt16(input1); | ||
+ | Console.WriteLine("The ASCII character " + input1 + " converts to the integer " + output1); | ||
+ | |||
+ | Console.ReadLine(); | ||
+ | |||
+ | /* Result: | ||
+ | The integer 65 converts to the ASCII character A | ||
+ | The ASCII character A converts to the integer 65 | ||
+ | */ | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=Revision Questions= | =Revision Questions= | ||
− | ''' | + | '''Don't forget, uppercase and lowercase have different values.''' |
<quiz display=simple> | <quiz display=simple> | ||
Line 46: | Line 90: | ||
- 95 | - 95 | ||
− | -22 | + | - 22 |
{'''ASCII is the abbreviation of:''' | {'''ASCII is the abbreviation of:''' | ||
Line 52: | Line 96: | ||
+ American Standard Code for Information Interchange | + American Standard Code for Information Interchange | ||
+ | - Australian Standard Code for Information Exchange | ||
+ | || ASCII was invented in ''America'' not ''Australia'', and the last word in ASCII is ''Interchange'' not ''Exchange'' | ||
- American Standard Code for Information Exchange | - American Standard Code for Information Exchange | ||
+ | || The last word in ASCII is ''Interchange'' not ''Exchange'' | ||
+ | - Australian Standard Code for Information Interchange | ||
+ | || ASCII was invented in ''America'' not ''Australia''. | ||
+ | |||
+ | { '''R has an ASCII value of 82 in denary. What is the ASCII value of W in denary?''' | ||
+ | | type="{}"} | ||
+ | { 87 _3 } | ||
+ | || W comes 5 positions later in the alphabet than R, so 82 + 5 = 87 | ||
− | - | + | {'''s has an ASCII value of 115 in denary. What is the ASCII value of k in denary?''' |
+ | | type="{}"} | ||
+ | { 107 _3 } | ||
+ | || k comes 8 positions earlier in the alphabet than s, so 115 - 8 = 107 | ||
+ | |||
+ | {'''Q has an ASCII value of 81 in denary. What is the ASCII value of Z in denary?''' | ||
+ | | type="{}"} | ||
+ | { 90 _3 } | ||
+ | || Z comes 9 positions later in the alphabet than Q, so 81 + 9 = 90 | ||
− | { ''' | + | {'''What is the ASCII character equivalent to the hexadecimal value 4A? ''(Case Sensitive)''''' |
| type="{}"} | | type="{}"} | ||
− | { | + | { J _1} |
+ | || 4 = 0100 and A = 10 = 1010, so 4A = 01001010 = 74, and 74 = J. ''(Look [[Conversions|here]] for more on conversions.)'' | ||
− | {''' | + | {'''What is the ASCII character equivalent to the hexadecimal value 7B?''' |
| type="{}"} | | type="{}"} | ||
− | { | + | { { _1 } |
− | {''' | + | {'''What is the shift in denary value between the upper and lower case ASCII character (E.g. A to a)?''' |
| type="{}"} | | type="{}"} | ||
− | { | + | { 32 _3} |
− | {'''True or False | + | {'''True or False: Unicode supports more characters than ASCII''' |
|type="()"} | |type="()"} | ||
− | + | + | + True |
− | - | + | - False |
</quiz> | </quiz> |
Latest revision as of 11:17, 9 May 2019
Contents
Overview
CraigNDave
https://www.youtube.com/watch?v=Eex82ogB8n8&index=1&list=PLCiOXwirraUBIKvhutnNnMkVTpQ_psPN2
Computer Science Tutor
https://www.youtube.com/watch?v=tdmeXcDX-Uc&list=PL04uZ7242_M6O_6ITD6ncf7EonVHyBeCm&index=6
Definition
ASCII stands for American Standard Code for Information Interchange. It is a character system that lets computers and devices to process letters, numbers and characters. It is represented by a 7-bit binary number that is either 0's or 1's. HTML (HyperText Markup Language) are based on ASCII (American Standard Code for Information Interchange). There are 128 characters that can be represented using ASCII.
Below is a table showing all of the characters that can be represented using ASCII
If you want to shift between the upper and lower case version of a character, you can add/minus 32 to the denary equivalent. E.g to change A to a, you would add 32 to 65, which would result in 97, and vice versa.
All of the ASCII codes can be found [here].
Extended ASCII
This used an additional bit (ie 8 bits) to allow for additional characters. Overall extended ASCII supports the original ASCII values but adds the following:
Unicode
Unicode is different coding system and is becoming more common. It is a 16-bit code, giving enough combinations to store every character in every alphabet (e.g. Urdu, Chinese) plus a vast range of other characters, control and communication codes.
The 16-bit code can represent 65536 different characters.
Unicode also added emoji compatibility, so now all emojis can be used as a unicode character. There are currently 2623 emojis contained within Unicode.
It maintains compatibility with ASCII by using the same code values as ASCII (ie codes 0-255 are the same as the ASCII table). So if you take ‘z’ and its ASCII value 122 (0111 1010 in binary), the unicode value is still 122 the binary will be 0000 0000 0111 1010.
All of the Unicode characters can be found [here].
Trivia
In many programming languages there are methods built in which are able to convert integers to ASCII characters and vice versa. Below are examples for Lua and C#. (Note: C# actually converts to Unicode, but from characters 0-255 this is identical to ASCII.)
Lua
1 local function convertToASCII(str)
2 return str:byte()
3 end
4
5 local function convertFromASCII(num)
6 return num:char()
7 end
8
9 print(convertToASCII("s")) -- > 115
10 print(convertFromASCII(115)) -- > s
C#
1 // Code to convert from an integer to an ASCII character.
2 int input = 65;
3 char output = Convert.ToChar(input);
4 Console.WriteLine("The integer " + input + " converts to the ASCII character " + output);
5
6 // Code to convert from an ASCII character to an integer.
7 char input1 = Convert.ToChar("A");
8 int output1 = Convert.ToInt16(input1);
9 Console.WriteLine("The ASCII character " + input1 + " converts to the integer " + output1);
10
11 Console.ReadLine();
12
13 /* Result:
14 The integer 65 converts to the ASCII character A
15 The ASCII character A converts to the integer 65
16 */
Revision Questions
Don't forget, uppercase and lowercase have different values.