Number Base Converter Formula

Understand the math behind the number base converter. Each variable explained with a worked example.

Formulas Used

Rem 2

rem_2 = mod(n, 2)

Rem 8

rem_8 = mod(n, 8)

Rem 16

rem_16 = mod(n, 16)

Log2 Val

log2_val = n > 0 ? floor(log(n) / log(2)) + 1 : 1

Log16 Val

log16_val = n > 0 ? floor(log(n) / log(16)) + 1 : 1

Variables

VariableDescriptionDefault
nDecimal Number255

How It Works

Number Base Conversion

Method: Repeated Division

To convert decimal to base b: 1. Divide n by b, record the remainder 2. Replace n with the quotient 3. Repeat until n = 0 4. Read remainders from bottom to top

Common Bases

  • Binary (base-2): 0, 1
  • Octal (base-8): 0-7
  • Decimal (base-10): 0-9
  • Hexadecimal (base-16): 0-9, A-F
  • Worked Example

    Analyze the number 255 in different bases.

    n = 255
    1. 01255 in binary: 11111111 (8 binary digits)
    2. 02255 in octal: 377 (last digit: 255 mod 8 = 7)
    3. 03255 in hex: FF (last digit: 255 mod 16 = 15 = F)
    4. 04Bits needed: floor(log2(255))+1 = 8

    Ready to run the numbers?

    Open Number Base Converter