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

    Frequently Asked Questions

    Why are number bases important?

    Different bases are used in different contexts: binary for computers, octal for Unix permissions, hexadecimal for memory addresses and colors, decimal for everyday use.

    How do I convert from decimal to binary?

    Repeatedly divide by 2 and record remainders. Read the remainders from bottom to top. For example, 13 → 6r1 → 3r0 → 1r1 → 0r1, so 13 = 1101 in binary.

    Why is 255 special in computing?

    255 is the largest 8-bit unsigned integer (11111111 in binary, FF in hex). It is the maximum value for each channel in 24-bit RGB color codes.

    Ready to run the numbers?

    Open Number Base Converter