cs101 lecture 03 hexadecimal numbers text representation
play

CS101 Lecture 03: Hexadecimal Numbers Text Representation - PDF document

1/23/13 CS101 Lecture 03: Hexadecimal Numbers Text Representation Hexadecimal Numbers Text Encoding ASCII and Unicode Aaron Stevens (azs@bu.edu) 23 January 2013 Computer Science What Youll Learn Today Computer Science A great


  1. 1/23/13 CS101 Lecture 03: Hexadecimal Numbers Text Representation Hexadecimal Numbers Text Encoding ASCII and Unicode Aaron Stevens (azs@bu.edu) 23 January 2013 Computer Science What You’ll Learn Today Computer Science  A great shortcut for writing binary numbers  How do computers store text information? 1

  2. 1/23/13 Just Call Me! Computer Science Here ’ s my phone number: 000101101111111110010110010000011001 � What ’ s wrong with this number? � – Hard to write on a napkin – Vulnerable to transcription errors – Won ’ t make you popular at parties Binary, Hexadecimal, Decimal Computer Science Each four bits map to a hex digit. Hexadecimal prefix 0x???? No inherent value, just means “ treat as a hex number ” 0x94D3 2

  3. 1/23/13 Hexadecimal to Decimal Computer Science Convert each hex digit into 4 bits. Convert binary to decimal. Example: 0x94D3 = 1001 0100 1101 0011 = 2 15 + 2 12 + 2 10 + 2 7 + 2 6 + 2 4 + 2 1 + 2 0 = 32768 + 4096 + 1024 + 128 + 64 + 16 + 2 + 1 = 38099 (decimal) Conversions Between Number Systems Computer Science Try some! http://www.mathsisfun.com/binary-decimal- hexadecimal-converter.html My phone number: 0x16FF96419 (or: 0001 0110 1111 1111 1001 0110 0100 0001 1001) 3

  4. 1/23/13 Binary Representations Computer Science Recall: a single bit can be either a 0 or a 1 What if you need to represent more than 2 choices? n bits can represent 2 n possible combinations Representing Text Computer Science A character set is a list of characters and the numbers (binary codes) used to represent each one. 4

  5. 1/23/13 The ASCII Character Set Computer Science ASCII stands for American Standard Code for Information Interchange ASCII originally used seven bits to represent each character, allowing for 128 unique characters Later extended ASCII evolved so that all eight bits were used. Computer Science The ASCII Character Set (7 bits) 5

  6. 1/23/13 ASCII Encoding Encoding Algorithm: Computer Science For each character: Example: Hello, world!  Find it ’ s ASCII code. H -> 0x48 -> 01001000 �  Convert to binary. e -> 0x65 -> 01100101 � l -> 0x6c -> 01101100 � l -> 0x6c -> 01101100 � o -> 0x6f -> 01101111 � , -> 0x2c -> 00101100 � -> 0x20 -> 00100000 � w -> 0x77 -> 01110111 � o -> 0x6f -> 01101111 � r -> 0x72 -> 01110010 � l -> 0x6c -> 01101100 � d -> 0x64 -> 01100100 � ! -> 0x21 -> 00100001 ASCII Decoding Computer Science 01000010 01100101 00100000 01110100 01110010 01110101 01100101 00100000 01110100 01101111 00100000 01111001 01101111 01110101 01110010 00100000 01110011 01100011 01101000 01101111 01101111 01101100 � Decoding Algorithm: For each 8 bits:  Convert Hex/decimal value  Lookup ASCII symbol � 01000010 -> 0x42 -> B � � 01100101 -> 0x65 -> e � 6

  7. 1/23/13 ASCII Decoding Computer Science 01000010 -> 0x42 -> B � 01100101 -> 0x65 -> e � 00100000 -> 0x20 -> � 01110100 -> 0x74 -> t � 01110010 -> 0x72 -> r � 01110101 -> 0x75 -> u � 01100101 -> 0x65 -> e � 00100000 -> 0x20 -> � 01110100 -> 0x74 -> t � 01101111 -> 0x6f -> o � 00100000 -> 0x20 -> � 01111001 -> 0x79 -> y � 01101111 -> 0x6f -> o � 01110101 -> 0x75 -> u � 01110010 -> 0x72 -> r � 00100000 -> 0x20 -> � 01110011 -> 0x73 -> s � 01100011 -> 0x63 -> c � 01101000 -> 0x68 -> h � 01101111 -> 0x6f -> o � 01101111 -> 0x6f -> o � 01101100 -> 0x6c -> l � Computer Science The Extended ASCII Character Set 7

  8. 1/23/13 ASCII Art Computer Science Can't You Take a Joke? :-) Computer Science Carnegie Mellon professor Scott E. Fahlman Proposed ASCII emoticons, Sept. 19, 1982. Source: http://www.wired.com/science/discoveries/news/2008/09/dayintech_0919 8

  9. 1/23/13 Unicode Character Set Computer Science Extended ASCII is not enough for international use. Unicode uses 16 bits per character How many characters can UNICODE represent? Unicode is a superset of ASCII -- the first 256 characters correspond exactly to the extended ASCII character set. Unicode Character Distribution Computer Science 9

  10. 1/23/13 Computer Science What You Learned Today Computer Science More encoding!  Hexadecimal Numbers  Character Sets  ASCII  Unicode 10

  11. 1/23/13 Announcements and To Do Computer Science  Homework 1 due tonight!  Readings :  Reed ch 5, pp 83-87, 89-90 (today)  Lab 2 on THURSDAY  Go to your scheduled lab time.  You must submit a document from the lab as evidence of attendance! 11

Recommend


More recommend