5.2 - Number Bases
- Number Base
- specifies how many different digts used in constructing a numeral and by how much to multiply each digit
- Decimal (Base 10)
- Has 10 different digits: 0,1,2,3,4,5,6,7,8,9. Base is 10: \(10^n\) where \(n \in \Z\)
- Binary (Base 2)
- Has two digits: 0,1. \(2^n\) where \(n \in \Z\)
- Hexadecimal (Base 16)
- 16 digits: 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F. \(16^n\) where \(n \in \Z\)
- n (Base n)
- some number \(a\) in base \(n\) represented as: \(a_n\)
- Decimal to Binary
- Take the decimal number and repeatedly divide by 2 until 0 is reached, writing the remainder each time
- Then read the remainders from the bottom to the top
- Decimal to Hexadecimal
- Can use the succesive division method (see above), but this time, dividing by 16
- Hexadecimal to binary
- Replace each hexadecimal digit by its binary equivalent (each should 4 bits)
- Why
- Hexadecimal digits (0-F) map to 0-15 in decimal, and this decimal range can be represented by exactly 4 binary digit
- Useful result:
- Binary to Hexadecimal
- Method
- add leading 0s to LHS of digit such that number of bits is multiple of 4 if necessary
- convert each block of 4 with hex equivalent
- Why hex good
- more convenient than binary
- takes up less space
- less error-prone
- less cumbersome
- needs 4x fewer digits than binary
- decimal needs 3.2x fewer = awkward factor to work with
- Usages:
- debugging (memory dumps)
- colours