You do not need a calculator for base conversions. With one simple grouping trick binary to hex becomes a mental math exercise. Every four binary digits map to exactly one hex digit. Every three binary digits map to one octal digit.
The grouping trick
Binary to hex: group into fours from the right.
Binary to octal: group into threes from the right.
Binary: 11010110
To hex: 1101 0110 → D6
To octal: 11 010 110 → 326
Pad the leftmost group with zeros if needed:
Binary: 10110
To hex: 0001 0110 → 16
To octal: 010 110 → 26
Why octal still exists
Octal (base 8) seems obsolete but appears in two important contexts:
Unix file permissions. chmod 755 uses three octal digits, each representing read (4), write (2), and execute (1) for owner, group, and others. The octal representation maps directly to three binary bits per digit: 7 = 111 (rwx), 5 = 101 (r-x).
C/JavaScript octal literals. A leading zero in some languages means octal: 0755 in C is 493 in decimal, not 755. In JavaScript strict mode, octal literals with a leading zero are a syntax error (use 0o755 instead).
Decimal conversion algorithm
For any base to decimal:
value = d[n]*base^n + d[n-1]*base^(n-1) + ... + d[1]*base^1 + d[0]*base^0
For decimal to any base: repeatedly divide and collect remainders.
function toBase(decimal, base) {
if (decimal === 0) return '0';
const digits = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
let result = '';
let n = decimal;
while (n > 0) {
result = digits[n % base] + result;
n = Math.floor(n / base);
}
return result;
}
function fromBase(str, base) {
const digits = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
return str.toUpperCase().split('').reduce((acc, char) =>
acc * base + digits.indexOf(char), 0
);
}
For converting between binary, octal, decimal, and hexadecimal with step-by-step explanations, I built a converter at zovo.one/free-tools/number-system-converter. It shows the conversion process, making it useful for learning and verifying manual calculations.
I'm Michael Lip. I build free developer tools at zovo.one. 500+ tools, all private, all free.
Top comments (0)