PYTHON PROGRAMING Week 15 – Tuesday
have a go Convert these denary numbers to binary: 23, 45, 62, 8, 14 Now convert them to hexadecimal Convert these hexadecimal numbers to binary: 3D, 1A, FF, 0F, 56 Now convert them to denary Work out these in binary: 23 + 45 62 + 8 8 * 14 14 * 62
last week Bitwise operators Binary addition Binary multiplication Hexadecimal (base 16) Denary to hex Hex to denary
today Targets!! Representing negative numbers in binary (Two’s complement) Binary subtraction Representing fixed point fractional numbers in binary File handling in Python
setting targets – comp1 & comp2 academic? maths? english?
twos complement Have you watched the videos? Representation of negative numbers Most significant bit holds sign 0 – positive 1 - negative Flip the bits Add 1 Negative 1 will always be all 1s in twos complement Smallest negative number will always be a leading 1 followed by zeroes Largest positive number will always be a leading zero followed by ones
binary addition– twos complement How do you think we do this?
binary subtraction – twos complement How do you think we do this? What is the advantage of this when it comes to designing computer architecture? NB Overflow adding two positives giving a negative number (eg 3 bit system 3 + 2) adding two negatives giving a positive number (eg 3 bit system -4 -7)
fixed point fractions in binary What is fixed point How do we represent the fractional part? .5 .1 .25 .01 .125 .001 .0625 .0001 …. How can we represent other fractions eg .75, .375 …
exercises Text book page 107 Questions 6-9 page 108 Questions 10-11 plus any of the activites
Python - file handling Codecademy Where are you? What is your target for this week? Try the file handling exercises on the web site Do I need to go through file handling programs? Smaller group? NB example programs and notes are also on the site
PLENARY How do we represent a negative number in binary? How many values can we represent in 4 bits? How many values can we represent in 8 bits? What is the largest positive number we can hold in a four bit signed system? What is the smallest negative number in a four bit signed system? What is the process for twos complement? How do we do binary subtraction? What is a fixed point number? How do we represent a fixed point number in binary? How did we get on with file handling?
tomorrow Revision for mock exam Exam questions Binary, hex, twos complement … Algorithm design tools Creating programs from designs
homework Have a look at revision topics and bring any questions tomorrow