Skip to main content

Number System Conversion

This page builds the easiest mental model for number systems and conversions. The goal is to fix the conversions in your mind for good. In math, we use division and multiplication to convert between number systems.

Odometer Mental Model

See all number systems with one model: the odometer. In an odometer,

  • Each position can start from minimum value of 0 to maximum value of base - 1.
  • When you increment a position past its max, it rolls over to 0. The next position then goes up by 1.
  • Then again the current position can be incremented from 0 to maximum value.

This is exactly how all number systems work. In binary, the allowed values are just 0 and 1. The numbers are just 0, 1, 10, 11, 100, 101, 110, 111, 1000, etc.

Box model for conversions

See each position in a number system as a box size. Each position holds a fixed number of boxes for that base. For example, in base 10, each position holds 10 boxes of different sizes.

boxes contain boxes

The boxes at a higher position are groups of boxes from the previous one. For example, in base 10, the box at position 2 (hundreds) holds 10 boxes. Each box, though, is itself 10 boxes of size 10 (tens).

PositionBinary (base-2)Decimal (base-10)Hexadecimal (base-16)
00-1 boxes of size 10-9 boxes of size 10-15 boxes of size 1
10-1 boxes of size 20-9 boxes of size 100-15 boxes of size 16
20-1 boxes of size 40-9 boxes of size 1000-15 boxes of size 256
30-1 boxes of size 80-9 boxes of size 1,0000-15 boxes of size 4,096
40-1 boxes of size 160-9 boxes of size 10,0000-15 boxes of size 65,536
50-1 boxes of size 320-9 boxes of size 100,0000-15 boxes of size 1,048,576

1.Greedy model conversion - Put as many items as you can in the boxes at each position. The boxes must always be full. Move the rest to the next position. If no box can be full, set the position value to 0.

2.Remainder Model - At each position, you divide by the items that fit in that box. For each division, the remainder is what doesn't fit the next box. It goes to the current position. For the next division, you re-divide the quotient. This works because the next position's boxes are always a multiple of the current ones. You just keep building groups of groups.

division is grouping

Division is just making groups of a certain size.

Keep dividing and you make groups of groups. This is how the remainder model maps to the box model.

  1. Non decimal to decimal conversion - Use the weighted sum model. Multiply each position's value by its box size. Add all the products to get the decimal value.
box-model-example

Mathematical Conversions

  1. From Base 10 - Divide by the destination base system and keep remainder for that position.
  2. To Base 10 - Multiply each position by the base system value for that position (box size) and add them.
conversion between non-decimal systems

You can convert between non-decimal systems in math. Multiplication and division are hard, though, in other number systems.

We always use decimal as a middle step.

Direction of Reading Digits

  1. Right to Left - Here you read the full number first. Then you know which digit's in which position. The value comes from the position, which is the box size.

  2. Left to Right - This is the intuitive way to read. It's also how computers convert. It assumes one digit and handles one position at a time.

    • Every position is processed assuming to be the last position.
    • Each position takes its value as is, since the last position has power 0.
    • Then the rest is multiplied by the base value.
Multiplying by base value

Multiplying the running total by the base is the same as shifting the whole number. You then add the new digit to it.