CS54 - Fall 2022 - Class 7
Lecture notes
admin
- assignment 3 due Sunday
- get started ASAP
- If you work with a partner, only once person needs to submit on Gradescope
midterm
- logistics
- in class on Wednesday
- pencil and paper exam (practice writing a few functions in SML on paper)
- closed books, notes, computer, etc.
- *except*, can bring two pages of notes (e.g., a double-sided piece of paper)
- Coverage: SML
- evaluate the function/what does the function do
- type signature
- code up functions
- Extra mentors on Monday and Tuesday for review support
- I will post *some* samples problems
- Intro SML reading and books also have others
recursion patterns
difference between [] and [[]]
decimal numbers
- most commonly used number systems have a "base"
- each digit in the number can range from 0...base-1
- each digit in the number has an index, starting at the right-most digit with 0 and working up to the left
- the contribution of the digit is:
base^index * value
- by summing up the contribution of all of the digits, we get the value of the number
- what is the base for our numbering system?
- 10
- for example
- 245 = 5*10^0 + 4*10^1 + 2*10^2
- 80498 = 8*10^0 + 9*10^1 + 4*10^2 + 0*10^3 + 8*10^4
other bases
- we can represent values by any base we'd like!
- A common one is CS, base 2, binary numbers:
- digits can only be a 0 or a 1
- for example, the following binary numbers:
- 101 = 1*2^0 + 0*2^2 + 1*2^2 = 5
- 11 = 1*2^0 + 1*2^1 = 3
- 10111 = 1*2^0 + 1*2^1 + 1*2^2 + 0*2^3 + 1*2^4 = 23
- 100001 = 1*2^0 + 1*2^5 = 33
- we can use any base we'd like, though
- base 9
- digits are numbers from 0 through 8
- 267 = 7*9^0 + 6*9^1 + 2*9^2 = 7 + 54 + 162 = 223
- base 200
- digits are numbers from 0 through 199
- 267 = 7*200^0 + 6*200^1 + 2*200^2 = 81,207
- note that even numbers written the same way can be interpreted differently!
- 2 55 167 = 167*200^0 + 55*200^2 + 2*200^2 = 91,167