/
CMPT 120 CMPT 120

CMPT 120 - PowerPoint Presentation

pasty-toler
pasty-toler . @pasty-toler
Follow
382 views
Uploaded On 2017-06-08

CMPT 120 - PPT Presentation

Topic Binary Encoding Part 1 Learning Outcome At the end of this course a student is expected to Manipulate binary encodings of simple data types Do conversions from binary  system to ID: 557301

numeral binary decimal system binary numeral system decimal ascii computer convert represented number counting memory numbers complement expressed table

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "CMPT 120" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

Slide1

CMPT 120

Topic:

Binary Encoding – Part 1Slide2

Learning Outcome

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 versaDetermine the range of representable values within binary systemDo additions and incremental counting within binary systemDecode/encode a bit string to/from its corresponding value (unsigned, 2's complement, ASCII)

2Slide3

Last Few Lectures

Iterative

Statements

while

loop

for

loop

range( ) built-in functionin operatorAlgorithms commonly used in CSRunning a count, running a sum, running a productComputing an averageBuilding a sequenceLooking for the maximum/minimumnumber occurrences of a specific element in a sequence

3Slide4

Today’s Menu

Binary

encoding

How characters are represented in memoryBinary and decimal numeral systemsIncremental counting and adding in those numeral systemsConverting binary numbers <-> decimal numbers

4

Binary

numeral

systemOctal numeral systemDecimal numeral system

Hexadecimal

numeral

systemSlide5

So far, we have seen that …

Computer memory

10010011101001000100010001000100010001000110001

0010101010100010010010010001000100110010001011011100100100100100100100000000110010100101010101000100100100100010001001100100010110111001001011101001010101010001001011000010100010011001000101101110010010101

010010010010010101001

integer

f

loating point

number

character

CPU instruction

colour

sound

5Slide6

Binary numeral system

We have already mentioned that

Computer

hardware functions using two voltage levelsSee link Computers and Voltage Levels in Week 2We represent these two voltage levels using 0’s and 1’s 0’s and 1’s are the 2 symbols of the binary numeral systemUsing binary numeral system makes talking about computer hardware (CPU architecture, CPU instruction set, memory content etc

…)

easier

As our previous slide demonstrated, what a sequence of 0’s and 1’s represent depends on the context, i.e. the

application that uses the information6Slide7

How is data

represented

in the computer memory?CharacterKey pressed on the keyboardCharacter represented by the key is mapped to a sequence of 8 bits in the ASCII section of the UNICODE table (see next slide) These 8 bits are then stored in computer memoryExample:What is ASCII?What is UNICODE?(see link on our course web site)

7Slide8

N

umeral

representation of

characterSource: http://www.hki.uni-koeln.de/sites/all/files/courses/5514/1000px-ASCII-Table.jpg

8Slide9

Source: http

://1.bp.blogspot.com/_e8aZh22zXKM/TMeR_fFL8aI/AAAAAAAAAAo/pIR08vVLkz0/s320/Hello_World.jpg

Example - Numerical representation of character

Padding: 9Slide10

What happens when we compare strings?

As we have already seen, Python compares strings by using the numerical representation of each character

For example:

Does “banana” come before or after “apple”, i.e., “banana” < “apple”?How humans answer the question:How a computer answer the question:

10Slide11

Numeral systems

As we saw in our ASCII table, a number can be expressed in a variety of numeral systems

For example:

Binary numeral system

Octal numeral

system

Decimal numeral

systemHexadecimal numeral system

11Slide12

Decimal numeral system

Deci

mal -> 10 (Base 10)

Ten digits: When counting: 12Slide13

Decimal numeral system

When adding:

13Slide14

Binary numeral system

Bin

ary -> 2 (Base 2)

Two digits:When counting:14Slide15

Binary numeral system

When adding

:

15Slide16

Convert binary to decimal

First, let’s examine how we

read numbers

expressed in the decimal numeral systemConsider the positional value of each digit in the decimal number below 2501416Slide17

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 0110000117Slide18

Convert decimal to binary

We could use a table and map the binary number to its decimal equivalent like we did when we mapped characters to their ASCII value equivalent

18Slide19

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 21319Slide20

Summary

In terms of 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 versaDetermine the range of representable values within binary systemsDo additions and incremental counting within binary systemsDecode/encode a bit string to/from its corresponding value (unsigned, 2's complement, ASCII)

20Slide21

Next Lecture

21

Binary

encodingHow integers are represented in memoryUnsignedSignedSign and magnitude1’s complement2's complement

How

floating point numbers

are represented in memoryHow many values (range) can they represent