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 : 1Log16 Val
log16_val = n > 0 ? floor(log(n) / log(16)) + 1 : 1Variables
| Variable | Description | Default |
|---|---|---|
n | Decimal Number | 255 |
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
Worked Example
Analyze the number 255 in different bases.
n = 255
- 01255 in binary: 11111111 (8 binary digits)
- 02255 in octal: 377 (last digit: 255 mod 8 = 7)
- 03255 in hex: FF (last digit: 255 mod 16 = 15 = F)
- 04Bits needed: floor(log2(255))+1 = 8
Ready to run the numbers?
Open Number Base Converter