Docsity

Understanding UTF-8 and Huffman Coding: A Comprehensive Guide, Lecture notes of Construction

Partial preview of the text

Download Understanding UTF-8 and Huffman Coding: A Comprehensive Guide and more Lecture notes Construction in PDF only on Docsity!

More Bits and Bytes

Huffman Coding

Encoding Text: How is it done?

ASCII, UTF, Huffman algorithm

UTF-8: All the alphabets in the world

§ Uniform Transformation Format: a variable-­‐width encoding that can represent every character in the Unicode Character set § 1,112,064 of them!!! § http://en.wikipedia.org/wiki/UTF-­‐ § UTF-­‐8 is the dominant character encoding for the World-­‐Wide Web, accounting for more than half of all Web pages. § The Internet Engineering Task Force (IETF) requires all Internet protocols to identify the encoding used for character data § The supported character encodings must include UTF-­‐8.

UTF is a VARIABLE LENGTH ALPHABET CODING § Remember ASCII can only represent 128 characters ( bits) § UTF encodes over one million § Why would you want a variable length coding scheme?

UTF-

A. 0000000001101010 B. 0000000011101010 C. 0000001010000111 D. 1010000011000111 What is the first Unicode value represented by this sequence? 11101010 10000011 10000111 00111111 11000011 10000000

UTF-

A. 1 B. 2 C. 3 D. 4 E. 5 How many Unicode characters are represented by this sequence? 11101010 10000011 10000111 00111111 11000011 10000000

© 2010 Lawrence Snyder, CSE

A Curious Story…

The Diving Bell and the Butterfly Jean-­‐Dominique Bauby

© 2010 Lawrence Snyder, CSE

Asking Yes/No Questions

§ A protocol for Yes/No questions § One blink == Yes § Two blinks == No

© 2010 Lawrence Snyder, CSE

Compare Two Orderings

§ How many questions to encode: Plus ça change, plus c'est la même chose? § Asking in Frequency Order: ESARINTULOMDPCFBVHGJQZYXKW 9 13

© 2010 Lawrence Snyder, CSE

Compare Two Orderings

§ How many questions to encode: Plus ça change, plus c'est la même chose? § Asking in Frequency Order: ESARINTULOMDPCFBVHGJQZYXKW § Asking in Alphabetical Order: ABCDEFGHIJKLMNOPQRSTUVWXYZ 12 16

An Algorithm

§ Spelling by going through the letters is an algorithm § Going through the letters in frequency order is a program (also, an algorithm but with the order specified to a particular case, i.e. FR) § The nurses didn’t look this up in a book … they invented it to make their work easier; they were thinking computationally © 2010 Lawrence Snyder, CSE

Coding can be used to do Compression

§ What is CODING? § The conversion of one representation into another § What is COMPRESSION? § Change the representation (digitization) in order to reduce size of data (number of bits needed to represent data) § Benefits § Reduce storage needed § Consider growth of digitized data. § Reduce transmission cost / latency / bandwidth § When you have a 56K dialup modem, every savings in BITS counts, SPEED § Also consider telephone lines, texting

How easy is it to do it?

§ Depends on data

§ Random data ⇒ hard

§ Example: 1001110100 ⇒?

§ Organized data ⇒ easy

§ Example: 1111111111 ⇒ 1 × 10

§ WHAT DOES THAT MEAN?

§ There is NO universally best

compression algorithm

§ It depends on how tuned the coding is

to the data you have

Can you lose information with Compression?

§ Lossless Compression is not guaranteed § Pigeonhole principle § Reduce size 1 bit ⇒ can only store ½ of data § Example § 000, 001, 010, 011, 100, 101, 110, 111 ⇒ 00, 01, 10, 11 § CONSIDER THE ALTERNATIVE § IF LOSSLESS COMPRESSION WERE GUARANTEED THEN § Compress file (reduce size by 1 bit) § Recompress output § Repeat (until we can store data with 0 bits) § OBVIOUS CONTRADICTION => IT IS NOT GUARANTEED.