Number Systems — worked example

Digital Logic 101 · Number Systems · Example

Convert 17310173_{10} into binary, octal, hex, BCD, and Gray code. Each base reuses the same value, and the conversions all go through the binary representation.

  1. Binary by repeated division. Divide by two; record the remainder; feed the quotient back. Read the remainders bottom-to-top.
    173÷2=86  r  186÷2=43  r  043÷2=21  r  121÷2=10  r  110÷2=5  r  05÷2=2  r  12÷2=1  r  01÷2=0  r  1\begin{aligned}173 &\div 2 = 86 \;\text{r}\; 1 \\ 86 &\div 2 = 43 \;\text{r}\; 0 \\ 43 &\div 2 = 21 \;\text{r}\; 1 \\ 21 &\div 2 = 10 \;\text{r}\; 1 \\ 10 &\div 2 = 5 \;\text{r}\; 0 \\ 5 &\div 2 = 2 \;\text{r}\; 1 \\ 2 &\div 2 = 1 \;\text{r}\; 0 \\ 1 &\div 2 = 0 \;\text{r}\; 1\end{aligned}
    Remainders bottom-up: 17310=101011012173_{10} = 10101101_{2}.
  2. Hex by regrouping. Split the 8-bit binary into two nibbles, then translate each nibble (0..15) into one hex digit (0..F).
    1010A    1101D    AD16\underbrace{1010}_{A} \;\; \underbrace{1101}_{D} \;\Rightarrow\; AD_{16}
    Cross-check: A16+D=1016+13=173A \cdot 16 + D = 10 \cdot 16 + 13 = 173.
  3. Octal by regrouping. Pad the binary with a leading zero to a multiple of three bits, then split into 3-bit groups.
    0102    1015    1015    2558\underbrace{0\,10}_{2} \;\; \underbrace{101}_{5} \;\; \underbrace{101}_{5} \;\Rightarrow\; 255_{8}
    Cross-check: 264+58+5=128+40+5=1732 \cdot 64 + 5 \cdot 8 + 5 = 128 + 40 + 5 = 173.
  4. BCD digit-by-digit. Encode each decimal digit of 173173 independently in 4 bits.
    1000170111300111 \to 0001 \quad 7 \to 0111 \quad 3 \to 0011
    17310=000101110011BCD\therefore 173_{10} = 0001\,0111\,0011_{\text{BCD}}
    Note that BCD is wider than straight binary: 12 bits versus 8 bits. The trade-off is human-readable digits at the cost of bit density.
  5. Gray by XOR. Apply g=n(n1)g = n \oplus (n \gg 1) bit-wise.
    n=10101101n1=01010110g=11111011\begin{aligned}n &= 1010\,1101 \\ n \gg 1 &= 0101\,0110 \\ g &= 1111\,1011\end{aligned}
    So 17310=11111011Gray173_{10} = 11111011_{\text{Gray}}. The XOR collapses to one Gray bit-flip per increment in nn, which is the entire point of the encoding.
Pick the path that fits the target base. Binary is repeated division; hex and octal regroup the binary; BCD encodes decimal digits independently; Gray comes straight from an XOR of the binary value with itself shifted right.

Try other values in the Simulate stage — every field updates live as you type or toggle bits.