Lecture 36 – Unit 6 – Under the Hood Binary Encoding – Part 2 CMPT 120 Lecture 36 – Unit 6 – Under the Hood Binary Encoding – Part 2
Review – “Computers use 0 and 1 to represent everything“ Computer memory: 100100111010010001000100010001000100010001100010010101000111111010010010001000100110010001011011100100100100100100100000000110010100101010101000100100100100010001001100100010110111001001011101001010101010001001011000010100010011001000101101110010010101 010010010010010101001 integer floating point number colour character CPU instruction sound
Review - Decimal numeral system Binary numeral system Decimal -> 10 (Base 10) Ten symbols (digits): 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Binary -> 2 (Base 2) Two symbols (bits): 0, 1 (bits -> binary digits)
Review - Decimal numeral system Binary numeral system Positional system When counting: Positional system When counting: 0 0 1 … 0 0 9 0 1 0 0 1 1 1 9 9 2 0 0 0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 … 102 101 22 21 20 100
How computers represent integers Which integer is this: bit byte A bit either contains a 0 or 1 A byte is 8 bits
How computers represent integers Which integer is this :
You try it! Which integer is this?
Decimal numeral system So far … Decimal numeral system Binary numeral system
Decimal numeral system Let’s try … Decimal numeral system Binary numeral system
What is 106 as a binary number?
Can you convert these? 1 00000001 2 00000010 3 00000011 4 00000100 5 00000101 6 00000110 7 00000111 8 00001000 9 _ _ _ _ _ _ _ _ 10 _ _ _ _ _ _ _ _ 11 _ _ _ _ _ _ _ _ 12 _ _ _ _ _ _ _ _ 13 _ _ _ _ _ _ _ _ 14 _ _ _ _ _ _ _ _ 15 _ _ _ _ _ _ _ _ 64 _ _ _ _ _ _ _ _ 255 _ _ _ _ _ _ _ _ 256 _ _ _ _ _ _ _ _
How can we read/write long binary numbers easily?
Hexadecimal Numbers
ASCII and Unicode
How computers represent characters We have already seen how computers deal with letters and characters … remember ASCII? Source: http://1.bp.blogspot.com/_e8aZh22zXKM/TMeR_fFL8aI/AAAAAAAAAAo/pIR08vVLkz0/s320/Hello_World.jpg See ASCII Table: https://www.ascii-code.com/
Unicode UTF - 8 ASCII uses 8 bits (1 byte) to encode characters using 0’s and 1’s How many different characters can we represent in ASCII with 8 bits (1 byte)? To type in other languages than English, we may need a lot more than that Unicode uses up to 4 bytes to handle more characters Let’s have a look: http://www.unicode.org/charts/
Other Character Encodings
I have a great idea! Let’s write a binary-decimal converter in Python How would we go about solving this problem?
Next Lecture Practice speaking binary and hexadecimal and a lot more! Bring your laptop!