UIL CS: Number Systems
This is part of the UIL CS study series. See also:
Main topic list: https://www.uiltexas.org/files/academics/UILCS-JavaTopicList2526.pdf
1. Number Systems
A. Converting from decimal to any base
Method: repeated division (for integers).
To convert decimal N to base b:
- Divide N by b.
- Record the remainder.
- Replace N with the quotient.
- Repeat until the quotient is 0.
- Read remainders bottom to top.
Example: convert 15610 to base 4
- 156÷4=39 remainder 0
- 39÷4=9 remainder 3
- 9÷4=2 remainder 1
- 2÷4=0 remainder 2
15610=21304
B. Shortcuts between binary, hex, and decimal
Binary to Decimal
Binary is base 2, so each bit represents a power of 2.
Example: 1011012
1⋅25+0⋅24+1⋅23+1⋅22+0⋅21+1⋅20=32+8+4+1=45
So 1011012=4510
Hex to Decimal
Hex is base 16.
Digits: 0-9, A=10, B=11, C=12, D=13, E=14, F=15.
Example: 2AF16
2⋅162+10⋅161+15⋅160=512+160+15=687
So 2AF16=68710
Binary to Hex shortcut (VERY common on UIL)
Group bits in chunks of 4 from the right.
Example: 1101011110012
Group: 110101111001
Convert each nibble:
- 1101=D
- 0111=7
- 1001=9
So: 1101011110012=D7916
C. Arithmetic in a base other than decimal
Example: addition in base 4
3124+2334
Work right to left:
- 2+3=5. In base 4, 5=114. Write 1 carry 1.
- 1+3+3=7. In base 4, 7=134. Write 3 carry 1.
- 3+2+1=6. In base 4, 6=124. Write 2 carry 1.
- carry 1
Answer: 3124+2334=121314
Note: Understand positional values (e.g., 2n, 16n).