Topics:
- number bases: decimal, binary, hexadecimal
- negative integer representations: signed magnitude, ones' complement, two's complement
Resources:
- review Make School's slides on number bases
- read BetterExplained's article on number systems and bases
- play with Dan Wolff's live-updating base conversion calculator
Challenges:
- practice conversions on number bases worksheet
- implement base conversion functions for positive numbers using starter code:
- implement
decode
- convert a number from any base to base 10 - implement
encode
- convert a number from base 10 to any base - implement
convert
- convert a number from any base to any other base - run
python bases.py number base1 base2
to testconvert
on a number- example:
python bases.py 42 10 2
gives the result101010
- example:
- run
pytest test_bases.py
to run the unit tests and fix any failures
- implement
Stretch Challenges:
- implement base conversion for negative binary numbers (using two's complement)
- implement base conversion for fractional numbers (using a radix point)