Back to Utilities

Number Base Converter

Convert numbers between binary, octal, decimal, and hexadecimal live.

Advertisement
Loading...

What this tool does

Number base conversion is the process of representing a number in different positional numeral systems. The most common bases in computing are binary (base-2), octal (base-8), decimal (base-10), and hexadecimal (base-16). This tool converts between these bases instantly as you type, making it easy to read memory addresses, color codes, network masks, and bit flags.

Binary uses only 0 and 1, matching the on/off state of transistors. Octal was popular in older systems with 12-bit or 36-bit word sizes, where 3 bits per digit mapped cleanly. Hexadecimal groups 4 bits per digit, making it the most compact human-readable representation of binary data, hence its use in memory dumps, color codes (#FF5733), and Unicode code points.

Usage Example

// Convert 255 to different bases
255 in binary:    11111111
255 in octal:     377
255 in decimal:   255
255 in hex:       FF

// In JavaScript
parseInt("ff", 16)        // 255
(255).toString(2)          // "11111111"
(255).toString(8)          // "377"
(255).toString(16)         // "ff"

// Bit manipulation
0xFF & 0x0F   // 0x0F (mask lower 4 bits)

Common Edge Cases

  • JavaScript number type is a 64-bit float with 53 bits of integer precision. Values above 2^53 lose precision in all bases.
  • Negative numbers are represented in two's complement for bitwise operations, but the sign is preserved in higher-level arithmetic.
  • Leading zeros in numeric literals are not allowed in most languages (0123 is decimal 123, not octal). Octal literals are usually prefixed with 0o (e.g., 0o377).
  • Floating-point numbers cannot be exactly represented in most bases other than the base they were entered in. 0.1 in decimal is a repeating fraction in binary.
  • Hex digits are conventionally uppercase (FF) or lowercase (ff); both are valid but the parser should be case-insensitive.

FAQ

Why is hexadecimal so common in programming?
Each hex digit represents exactly 4 binary digits (bits), so a byte (8 bits) is two hex digits. This makes hex the most compact human-readable way to inspect binary data, and it is used in memory addresses, color codes, and bit masks.
What is the difference between signed and unsigned integers?
Signed integers reserve one bit for the sign, halving the positive range. Unsigned integers use all bits for the value, doubling the positive range. For example, an 8-bit signed integer ranges from -128 to 127, while unsigned ranges from 0 to 255.
How do I convert a large number to binary manually?
Repeatedly divide by 2 and collect the remainders in reverse order. For example, 13 in binary: 13/2=6 r1, 6/2=3 r0, 3/2=1 r1, 1/2=0 r1, reading bottom to top: 1101.
Advertisement