lecture 1
play

LECTURE 1 INTRO & NUMBER SYSTEMS MCS 260 Fall 2020 David Dumas - PowerPoint PPT Presentation

LECTURE 1 INTRO & NUMBER SYSTEMS MCS 260 Fall 2020 David Dumas / ZOOM 101 Scale the slides to your zoom window / ZOOM 102 You can raise your hand to request aenon / MCS 260: INTRO TO COMPUTER SCIENCE Instructor: Prof. David


  1. LECTURE 1 INTRO & NUMBER SYSTEMS MCS 260 Fall 2020 David Dumas /

  2. ZOOM 101 Scale the slides to your zoom window /

  3. ZOOM 102 You can raise your hand to request a�en�on /

  4. MCS 260: INTRO TO COMPUTER SCIENCE Instructor: Prof. David Dumas ⟨ ddumas@uic.edu ⟩ TA: Jennifer Vaccaro ⟨ jvacca4@uic.edu ⟩ TA: David (Hai) Wang ⟨ hwang202@uic.edu ⟩ /

  5. IMMEDIATE ACTION ITEMS Read the syllabus (Yes, the en�re thing. Yes, it is boring.) Check the blackboard course site regularly. /

  6. PYTHON /

  7. Python is a computer programming language. #3 most popular programming language in TIOBE Extensive use at Dropbox, Instagram, Ne�lix, ... #1 most popular (by far) in a 2018 survey of data science / machine learning professionals ( source ) /

  8. Learning Python (version 3.6 or higher) is a key focus of MCS 260. Most of our discussion of general computer science concepts will be based on the way they are seen and used in Python. /

  9. PYTHON VERSIONS In this course we only use Python 3. The transi�on from Python 2 to Python 3 was a major milestone, with incompa�ble changes. Python 2 support ended in January 1, 2020. /

  10. LIVE DEMO TIME Excerpt of xkcd by Randall Munroe CC-BY-NC-2.5 /

  11. NUMBER SYSTEMS /

  12. Humans usually use the decimal number system, also known as base . 10 In this system there is a s place, a s 10 0 10 1 = 1 = 10 place, a s place, etc. 10 2 = 100 There are digits with values . 10 0, 1, … , 9 In decimal, means: 312 10 2 10 1 10 0 312 = 3 × + 1 × + 2 × /

  13. For any whole number there is a number system 𝑐 > 1 called base where the place values are , , , etc. 𝑐 0 𝑐 1 𝑐 2 𝑐 In base there are digits with values . 𝑐 𝑐 0, 1, … , 𝑐 − 1 In mathema�cs, it is common to use a subscript to indicate the base. So means the base number with digits . 201 5 5 2, 0, 1 /

  14. is equal to the decimal number : 201 5 51 5 2 5 1 5 0 201 5 = 2 × + 0 × + 1 × = 2 × 25 + 1 × 1 = 51 /

  15. In computer science, three non-decimal number systems are o�en encountered. Binary , or base . 2 Hexadecimal , or base . 16 Octal , or base . (Least common.) 8 /

  16. BINARY The digits are and . A binary digit is called a bit . 0 1 The place values are , , , , , etc. 1 2 4 8 16 Example: means 1001 2 1 × 8 + 0 × 4 + 0 × 2 + 1 × 1 = 9 In Python, binary numbers are indicated by preceding the digits with . 𝟷 𝚌 So the previous example would be wri�en . 𝟷 𝚌 𝟸𝟷𝟷𝟸 /

  17. We can convert to binary using integer division and remainder. Integer division means divided by , discarding the remainer. 𝑦 / /2 𝑦 2 e.g. , . 7/ /2 = 3 6/ /2 = 3 Remainder means the remainder when is divded by . 𝑦 %2 𝑦 2 , . 7%2 = 1 6%2 = 0 /

  18. To convert a number to binary, just keep track of the remainders when you repeatedly integer-divide by . 2 𝑦 𝑦 / /2 𝑦 %2 312 156 0 156 78 0 78 39 0 39 19 1 19 9 1 9 4 1 4 2 0 2 1 0 1 0 1 So , i.e. 312 = 𝟷 𝚌 𝟸𝟷𝟷𝟸𝟸𝟸𝟷𝟷𝟷 . 312 = 256 + 32 + 16 + 8 /

  19. /

  20. Binary is not ideal for human consump�on because of its low informa�on density. e.g. . 9754 = 𝟷 𝚌 𝟸𝟷𝟷𝟸𝟸𝟷𝟷𝟷𝟷𝟸𝟸𝟷𝟸𝟷 Hexadecimal addresses this, giving a more condensed way of expressing a sequence of bits. /

  21. HEXADECIMAL Hexadecimal or hex is a condensed representa�on of binary, with one symbol for each -bit block. 4 Each -bit block is just a number between 4 and . We use hex digits 𝟷 𝚌 𝟷𝟷𝟷𝟷 = 0 𝟷 𝚌 𝟸𝟸𝟸𝟸 = 15 , : 0 … 9 𝐵 … 𝐺 Digit 0 1 2 3 4 5 6 7 Value 0 1 2 3 4 5 6 7 Bit block 0000 0001 0010 0011 0100 0101 0110 0111 Digit 8 9 A B C D E F Value 8 9 10 11 12 13 14 15 Bit block 1000 1001 1010 1011 1100 1101 1110 1111 /

  22. HEXADECIMAL Hexadecimal or hex is a condensed representa�on of binary, with one symbol for each -bit block. 4 Each -bit block is just a number between 4 and . We use hex digits 𝟷 𝚌 𝟷𝟷𝟷𝟷 = 0 𝟷 𝚌 𝟸𝟸𝟸𝟸 = 15 , : 0 … 9 𝐵 … 𝐺 Digit 0 1 2 3 4 5 6 7 Value 0 1 2 3 4 5 6 7 Bit block 0000 0001 0010 0011 0100 0101 0110 0111 Digit 8 9 A B C D E F Value 8 9 10 11 12 13 14 15 Bit block 1000 1001 1010 1011 1100 1101 1110 1111 /

  23. In Python nota�on, hexadecimal numbers begin with , followed by the digits. 𝟷 𝚢 So means 𝟷 𝚢 𝟺 𝚏 3 e 0011 1110 ⟶ 𝟷 𝚌 𝟷𝟷𝟸𝟸𝟸𝟸𝟸𝟷 = 62 Hexadecimal is also base . Another way to see 16 : 𝟷 𝚢 𝟺 𝚏 16 1 16 0 𝟷 𝚢 𝟺 𝚏 = 𝟺 × + 𝚏 × = 3 × 16 + 14 × 1 = 62 /

  24. Aside: In decimal we some�mes separate groups of digits with punctua�on for easier reading. e.g. in the USA one million is o�en wri�en " ". 1,000,000 In Python nota�on the underscore " " can be used as a _ separator. 𝟷 𝚌 𝟸𝟸𝟸𝟸 _ 𝟷𝟸𝟷𝟷 _ 𝟷𝟷𝟸𝟷 _ 𝟷𝟸𝟷𝟷 _ 𝟷𝟷𝟷𝟷 = 𝟷 𝚢𝚐 𝟻𝟹𝟻𝟷 = 𝟸 _ 𝟷𝟷𝟷 _ 𝟷𝟷𝟷 /

  25. When conver�ng binary to hex, the number of bits may not be a mul�ple of at first. In this case we need 4 to add some zeros on the le�: 𝟷 𝚌 𝟸𝟷𝟸𝟷𝟸 = 𝟷 𝚌 𝟷𝟷𝟷𝟸𝟷𝟸𝟷𝟸 = 𝟷 𝚌 𝟷𝟷𝟷𝟸 _ 𝟷𝟸𝟷𝟸 = 𝟷 𝚢 𝟸𝟼 /

  26. To convert a decimal number to hex, one way is to convert to binary and group bits. An alterna�ve is to repeatedly integer-divide by 16 and use the remainders: 𝑦 𝑦 / /16 𝑦 %16 62 3 14 3 0 3 Therefore 62 = 𝟷 𝚢 𝟺 𝚏 /

  27. OCTAL Octal or base is similar but we divide a binary 8 number into blocks of bits, to using to 3 0, … , 7 represent blocks of bits. 3 In Python nota�on, octal numbers begin with 𝟷 𝚙 followed by the digits. (That's numeral zero followed by lower case le�er o.) Example: 𝟷 𝚙 𝟾𝟾𝟼 = 𝟷 𝚌 𝟸𝟸𝟸 _ 𝟸𝟸𝟸 _ 𝟸𝟷𝟸 = 509 /

  28. Octal is most commonly seen when se�ng file permissions on unix/Linux, where bits are naturally 9 divided into groups of . 3 3 e.g. chmod 600 secrets.dat /

  29. REFERENCES The first steps in working with Python are covered in Sec�on 1.2 of Downey . Binary and hexadecimal are covered in Sec�on 1.1 of Brookshear & Brylow . ACKNOWLEDGEMENTS Some of today's lecture was based on teaching materials developed for MCS 260 by Jan Verschelde . REVISION HISTORY 2020-08-24 Corrected typo in octal example 2020-08-23 Ini�al publica�on /

Recommend


More recommend