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 NN to base bb:

  1. Divide NN by bb.
  2. Record the remainder.
  3. Replace NN with the quotient.
  4. Repeat until the quotient is 00.
  5. Read remainders bottom to top.

Example: convert 15610156_{10} to base 44

  • 156÷4=39156 \div 4 = 39 remainder 00
  • 39÷4=939 \div 4 = 9 remainder 33
  • 9÷4=29 \div 4 = 2 remainder 11
  • 2÷4=02 \div 4 = 0 remainder 22

15610=21304156_{10} = 2130_{4}


B. Shortcuts between binary, hex, and decimal

Binary to Decimal

Binary is base 22, so each bit represents a power of 22.

Example: 1011012101101_2

125+024+123+122+021+120=32+8+4+1=451\cdot2^{5} + 0\cdot2^{4} + 1\cdot2^{3} + 1\cdot2^{2} + 0\cdot2^{1} + 1\cdot2^{0} = 32 + 8 + 4 + 1 = 45

So 1011012=4510101101_2 = 45_{10}

Hex to Decimal

Hex is base 1616.

Digits: 00-99, A=10A=10, B=11B=11, C=12C=12, D=13D=13, E=14E=14, F=15F=15.

Example: 2AF162AF_{16}

2162+10161+15160=512+160+15=6872\cdot16^{2} + 10\cdot16^{1} + 15\cdot16^{0} = 512 + 160 + 15 = 687

So 2AF16=687102AF_{16} = 687_{10}

Binary to Hex shortcut (VERY common on UIL)

Group bits in chunks of 44 from the right.

Example: 1101011110012110101111001_2

Group: 1101  0111  10011101\;0111\;1001

Convert each nibble:

  • 1101=D1101 = D
  • 0111=70111 = 7
  • 1001=91001 = 9

So: 1101011110012=D7916110101111001_2 = D79_{16}


C. Arithmetic in a base other than decimal

Example: addition in base 44

3124+2334\begin{array}{r} 312_{4} \\ + 233_{4} \\ \hline \end{array}

Work right to left:

  • 2+3=52 + 3 = 5. In base 44, 5=1145 = 11_{4}. Write 11 carry 11.
  • 1+3+3=71 + 3 + 3 = 7. In base 44, 7=1347 = 13_{4}. Write 33 carry 11.
  • 3+2+1=63 + 2 + 1 = 6. In base 44, 6=1246 = 12_{4}. Write 22 carry 11.
  • carry 11

Answer: 3124+2334=121314312_{4} + 233_{4} = 12131_{4}

Note: Understand positional values (e.g., 2n2^{n}, 16n16^{n}).