Topic: Binary Encoding – Part 1 CMPT 120 Topic: Binary Encoding – Part 1
Last Lecture File I/O File input -> reading data from a file File output -> writing data to a file
Learning Outcomes At the end of this course, a student is expected to: Manipulate binary encodings of simple data types. Do conversions from binary system to decimal and vice versa Determine the range of representable values within binary system Do additions and incremental counting within binary system Decode/encode a bit string to/from its corresponding value (unsigned, 2's complement, ASCII)
Decimal numeral system Today’s Menu Binary Encoding How characters are represented in computer memory How numbers are represented in computer memory But before to do this, we need to introduce decimal and binary numeral systems Counting and adding numbers in these numeral systems Converting binary numbers <-> decimal numbers Decimal numeral system Binary numeral system
So far, we have seen that … Computer memory: 100100111010010001000100010001000100010001100010010101010100010010010010001000100110010001011011100100100100100100100000000110010100101010101000100100100100010001001100100010110111001001011101001010101010001001011000010100010011001000101101110010010101 010010010010010101001 integer colour floating point number character CPU instruction sound
Sequences of 0’s and 1’s We have already mentioned that Computer hardware functions using two voltage levels See link Computers and Voltage Levels in Week 2 We represent these two voltage levels using 0’s and 1’s As our previous slide demonstrated, what a sequence of 0’s and 1’s represents depends on the context So, let’s have a look at what could a sequence of 0’s and 1’s represent
How characters are represented in computer memory Source: http://1.bp.blogspot.com/_e8aZh22zXKM/TMeR_fFL8aI/AAAAAAAAAAo/pIR08vVLkz0/s320/Hello_World.jpg
Numeral representation of characters (UNICODE) Source: http://www.hki.uni-koeln.de/sites/all/files/courses/5514/1000px-ASCII-Table.jpg
Padding Notice ... From Slide 7: From ASCII Table: H -> 01001000 versus H -> 1001000
How numbers are represented in computer memory Let’s introduce a few numeral systems As we saw in our ASCII table, a character can be expressed in a variety of numeral systems For example: Hexadecimal numeral system Binary numeral system Decimal numeral system Octal numeral system
Decimal numeral system Decimal -> 10 (Base 10) Ten digits: When counting:
Decimal numeral system When adding:
Binary numeral system Binary -> 2 (Base 2) Two digits: Using the symbols of the binary numeral system makes it easier to talk about computer hardware (CPU architecture, CPU instruction set, memory content etc…) Binary -> 2 (Base 2) Two digits: When counting:
Binary numeral system When adding:
Convert binary to decimal First, let’s examine how we read numbers expressed in the decimal numeral system Consider the positional value of each digit in the decimal number below 25014
Convert binary to decimal Applying the same algorithm, let’s convert the following number expressed in binary numeral system to its equivalent in decimal numeral system 01100001
Convert decimal to binary We could use a table and map the binary number to its decimal number equivalent like we did when we mapped characters to their binary number equivalent
Convert decimal to binary Applying the same algorithm as the one described in our reading, let’s convert the following number expressed in decimal numeral system to its equivalent in binary numeral system 213
Decimal numeral system Summary Binary Encoding How characters are represented in computer memory How numbers are represented in computer memory But before to do this, we need to introduce decimal and binary numeral systems Counting and adding numbers in these numeral systems Converting binary numbers <-> decimal numbers Decimal numeral system Binary numeral system
Next Lecture Binary encoding How numbers integers are represented in computer memory Unsigned integers Signed integers Sign and magnitude 1’s complement 2's complement How many values (range of values) can they represent