DSCI 220, 2025 W1
October 14, 2025
DON’T FORGET TO EXPLAIN THE MAGIC TRICK!
Consider an encoding into binary:
\[(b_{k-1}\dots b_1 b_0)_2=\sum_{i=0}^{k-1} b_i 2^i,\quad b_i\in\{0,1\}\]
Claim: With \(b\) bits we can represent \(2^b\) values.
int (pure Python): arbitrary precision (variable width)
NumPy / Pandas arrays: fixed-width datatypes (int8, int32, int64, uint64, …)
Demo:
Consider addition, with 4 bits:
Punchline: Overflow occurs when the number you want to represent is too big to fit into the space you’ve reserved for it.
Unsigned integers are represented by their encodings as discussed above.
\(b\) bits typically represent values \([0..2^b-1]\).
Signed integers have a different encoding (that we won’t discuss) but we can still guess the values that can be encoded:
\(b\) bits typically represent values ____________.
For each, compute bits needed or max value:
In words: what does \(\lceil\log_2 N\rceil\) tell you?