UUID Studio

Number Base Converter

Convert between binary, octal, decimal, and hexadecimal.

  • 🔒 No data stored or uploaded
  • âš¡ 100% client-side
  • 🆓 Free, no account

Need more than one tool at a time? Open the full Workbench - or press Ctrl+K to jump to any tool.

Create or edit JSON here (syntax colors), then format, validate, or convert - same as MongoDB $binary UUID blobs on the Convert tab once detected.

New document

About Number Base Converter

Binary, octal, decimal and hexadecimal are four ways of writing the same integer. Hex is the one that matters most in practice, because it maps cleanly onto bytes: one hex digit is exactly four bits, so two hex digits is one byte, and a byte boundary always falls on a digit boundary. Binary makes individual bits visible; octal survives mainly in Unix file permissions.

That four-bits-per-digit property is what makes hex the default for anything byte-oriented - colour values, memory addresses, hashes, bitmasks, protocol fields. Reading 0xFF as 255 and 0x0F as 15 becomes automatic quickly, and the grouping means you can spot a byte boundary at a glance in a way decimal never allows.

Octal's one common use is file permissions, and the reason it fits is the same: each octal digit is exactly three bits, and Unix permissions come in groups of three - read, write, execute - for user, group and other. 755 is rwxr-xr-x because 7 is 111 and 5 is 101. A leading zero also means octal in C, Java and older JavaScript, which is why 0755 and 755 are different numbers in those languages.

The practical trap in conversion is language-specific. JavaScript's parseInt guesses the radix from the prefix unless you pass one explicitly, so parseInt('08') has historically been surprising and parseInt('0x10') is 16 rather than 0. Always pass the radix. And JavaScript's bitwise operators coerce to 32-bit signed integers, so shifting a value above 2^31 silently produces a negative number - use BigInt for anything wider.

Conversion runs in your browser and nothing is transmitted.

How to use the Number Base Converter

  1. Enter the value and say which base it is in - prefixes like 0x, 0b and 0o are recognised.
  2. Read the equivalents in every base at once, with the bit width shown.
  3. For bitmask work, look at the binary form to see exactly which bits are set.
  4. Copy the representation your target language expects, with or without its prefix.

Examples

  • Decimal
    255
  • Hex
    0xff
  • Binary
    0b11111111

Number Base Converter in code

The same operation this tool performs, in the languages you are most likely to need it.

JavaScript
// To a string in another base
(255).toString(2);     // "11111111"
(255).toString(16);    // "ff"
(255).toString(8);     // "377"

// From a string - ALWAYS pass the radix
parseInt("ff", 16);    // 255
parseInt("11111111", 2);
parseInt("0x10", 16);  // 16
parseInt("0x10");      // 16 - guessed from the prefix
parseInt("08");        // 8 today, but was 0 in old engines

// Literals
0xff; 0b11111111; 0o377;

// Bitwise operators coerce to 32-bit SIGNED integers:
2 ** 31 | 0;           // -2147483648  <- silently negative
// Use BigInt beyond 32 bits:
BigInt("0xffffffffff") >> 8n;

// Zero-pad to a byte boundary
(10).toString(16).padStart(2, "0");   // "0a"
Python
bin(255)      # '0b11111111'
hex(255)      # '0xff'
oct(255)      # '0o377'

int("ff", 16)         # 255
int("11111111", 2)
int("0xff", 0)        # 255 - base 0 infers from the prefix

# Formatting with padding, no prefix
f"{255:08b}"          # '11111111'
f"{10:02x}"           # '0a'
f"{255:#x}"           # '0xff'

# Python integers are arbitrary precision, so no 32-bit
# overflow surprises - and >> on a negative int sign-extends.
(1 << 200).bit_length()   # 201
Command line
# printf handles most conversions
printf '%x\n' 255        # ff
printf '%o\n' 255        # 377
printf '%d\n' 0xff       # 255

# Bash arithmetic with an explicit base
echo $((16#ff))          # 255
echo $((2#11111111))     # 255
echo $((8#377))          # 255

# bc for binary output
echo 'obase=2; 255' | bc

# File permissions - the practical use of octal
stat -c '%a %A' file     # 755 -rwxr-xr-x
chmod 755 file           # 7=111 rwx, 5=101 r-x

When you need this

  • Reading a bitmask or flags field to see which bits are set.
  • Converting a colour between hex and decimal RGB components.
  • Translating a Unix permission mode between octal and symbolic form.
  • Checking what a hex value from a protocol dump or register means in decimal.
  • Working out how many bits a value needs, and whether it fits a given field.

Common problems and what causes them

parseInt without a radix
parseInt guesses from the prefix, so parseInt('0x10') is 16, and historically parseInt('08') was 0 because the leading zero implied octal. Always pass the radix explicitly - it costs nothing and removes the whole class of bug.
JavaScript bitwise operators truncating to 32 bits
|, &, <<, >> and ~ coerce their operands to 32-bit signed integers, so any value at or above 2^31 becomes negative and anything above 2^32 loses its high bits entirely. Use BigInt for wider values.
A leading zero meaning octal
In C, Java and older JavaScript, 0755 is octal 755 (decimal 493), not decimal 755. This bites when a permission mode or a zero-padded identifier is written as a numeric literal instead of a string.
Hex digits and byte counts confused
Two hex digits is one byte. A 32-byte key is 64 hex characters, so a 32-character hex string is 16 bytes - the most common cause of a key-length error in crypto libraries.
Missing zero padding
Formatting byte 0x0a without padding gives 'a', which shifts every following character in a hex dump and produces an odd-length string. Pad to two digits per byte.
Signed versus unsigned interpretation
0xFF is 255 unsigned and -1 as a signed 8-bit value; 0xFFFFFFFF is 4294967295 or -1 depending on width. The bits are identical - what differs is the interpretation, so know the field width before reading the value.

FAQ

Why is hexadecimal used so much in programming?
Because one hex digit is exactly four bits, so two digits is exactly one byte and byte boundaries always land on digit boundaries. That makes hex far easier to read against binary data than decimal, where no digit corresponds to a fixed number of bits.
What do the 0x, 0b and 0o prefixes mean?
0x is hexadecimal, 0b binary and 0o octal. A bare leading zero also means octal in C, Java and older JavaScript - which is why 0755 and 755 are different numbers there. Modern languages prefer the explicit 0o form.
How many hex characters is a 256-bit value?
64. Divide bits by 8 to get bytes (32), then multiply by 2 for hex characters. Getting this backwards is the usual cause of 'invalid key length' errors.
Why is octal still used for file permissions?
Because each octal digit is exactly three bits and Unix permissions come in groups of three - read, write, execute - for user, group and other. 755 is rwxr-xr-x because 7 is binary 111 and 5 is 101.
Why does my JavaScript bit shift produce a negative number?
Bitwise operators convert to 32-bit signed integers, so a value with bit 31 set reads as negative. 2**31 | 0 is -2147483648. Use BigInt when you need more than 32 bits.
Does it support negative numbers?
No - only non-negative integers are supported, since binary/octal/hex representations of negative numbers depend on a bit width and signedness convention this tool doesn't assume.

Related reading