Number Base Converter

Type a value in any field and binary, octal, decimal and hex update together. Large integers and negative numbers are handled exactly, and conversions between any bases from 2 to 36 come with the working shown.

The prefixes 0b, 0o and 0x, spaces and underscores (_) are ignored. A leading - makes the number negative. Whole numbers only.

Arbitrary base conversion (base 2-36) with working

What a base is, and how to read place values

A base (or radix) says how many distinct digits a number system uses and therefore how much each place is worth compared with the one to its right. In everyday decimal, "253" means 2 x 102 + 5 x 101 + 3 x 100. Binary "1101" is read in exactly the same way: 1 x 23 + 1 x 22 + 0 x 21 + 1 x 20 = 8 + 4 + 0 + 1 = 13. In any base, multiply each digit by the base raised to its position and add the results to get the decimal value. The "positional expansion" shown in the working below is that sum.

Going the other way, to convert a decimal number to base N, divide by N repeatedly and read the remainders from last to first. For 13: 13 / 2 is 6 remainder 1, 6 / 2 is 3 remainder 0, 3 / 2 is 1 remainder 1, and 1 / 2 is 0 remainder 1. Reading the remainders backwards gives 1101. They come out in reverse because the first remainder is the lowest place, the ones digit.

Reference table: 0 to 16

DecimalBinaryOctalHex
00000000
10000111
20001022
30001133
40010044
50010155
60011066
70011177
801000108
901001119
100101012A
110101113B
120110014C
130110115D
140111016E
150111117F
16100002010

One hex digit matches exactly four bits (a nibble) and one octal digit matches three bits. Converting binary to hex therefore needs no arithmetic: split the bits into groups of four and look each up. For 1011 0101 the groups are B and 5, so the value is B5. To go back, expand each hex digit into four bits.

Why computers use binary

Digital circuits are most reliable when they only have to tell two clearly separated states apart, such as a high or low voltage, so binary is the natural base. Long binary strings are hard for people to read, so addresses, error codes and color values are written in hex, which packs four bits into one character, and Unix file permissions use octal, which packs three. The number 1,000 is 1111101000 in binary (10 digits), 1750 in octal and 3E8 in hex, getting shorter each time.

Powers of two

These values are computed with BigInt when the page is built, so they stay exact even beyond 253.

ExponentDecimalHex
2^011
2^122
2^244
2^388
2^41610
2^53220
2^66440
2^712880
2^8256100
2^101,024400
2^124,0961000
2^1665,53610000
2^201,048,576100000
2^2416,777,2161000000
2^312,147,483,64880000000
2^324,294,967,296100000000
2^539,007,199,254,740,99220000000000000
2^639,223,372,036,854,775,8088000000000000000
2^6418,446,744,073,709,551,61610000000000000000

28 = 256 is the number of values in one byte (0 to 255), and 216 = 65,536 is the number of TCP/UDP port numbers (0 to 65535). 253 matters for JavaScript: ordinary numbers are 64-bit floating-point values and can hold every integer exactly only up to 253 - 1 = 9,007,199,254,740,991. Beyond that some integers cannot be represented, which is why this converter does its arithmetic with BigInt.

How precision, negatives and fractions are handled

Negative numbers and two's complement

Most computers store negative integers in two's complement. In n bits, -x is stored as 2n - x. In 8 bits, -1 is 256 - 1 = 255 = 11111111 (hex FF), -128 is 10000000 (80) and +127 is 01111111 (7F). The same pattern FF means 255 when read as unsigned and -1 when read as signed, so a bit pattern means nothing until you decide its width and signedness. When you enter a negative number above, rows for 8, 16, 32 and 64 bits are listed, and a row is omitted if the value does not fit in that width.

WidthSigned minimumSigned maximumUnsigned maximum
8 bits-128127255
16 bits-32,76832,76765,535
32 bits-2,147,483,6482,147,483,6474,294,967,295
64 bits-9,223,372,036,854,775,8089,223,372,036,854,775,80718,446,744,073,709,551,615

Everyday uses: color codes and chmod

The web color #FF8800 is the red, green and blue bytes FF, 88 and 00 written together. In decimal that is red 255, green 136 and blue 0 (0x88 = 8 x 16 + 8 = 136). A Unix permission such as 755 is read in octal, and each digit is the sum of read = 4, write = 2 and execute = 1.

OctalBinaryPermission
0000---
1001--x
2010-w-
3011-wx
4100r--
5101r-x
6110rw-
7111rwx

For example, chmod 755 gives the owner 7 (rwx), the group 5 (r-x) and others 5 (r-x), written rwxr-xr-x and 111 101 101 in binary. chmod 644 is rw-r--r--: only the owner can write, everyone can read.

Checked examples

  1. Binary to decimal. 10110101 in binary is 128 + 32 + 16 + 4 + 1 = 181, which is B5 in hex (1011 = B, 0101 = 5).
  2. Hex to decimal. 1F4 in hex is 1 x 256 + 15 x 16 + 4 = 500.
  3. Octal to binary. 755 in octal is 111 101 101 in binary: expand each octal digit to three bits.
  4. Base 36. ZZ in base 36 is 35 x 36 + 35 = 1,295. Going the other way, 3,000 divided by 36 gives 83 remainder 12 (C), and 83 divided by 36 gives 2 remainder 11 (B), so 3,000 is 2BC in base 36.
  5. A large number. 9,007,199,254,740,993 is 20000000000001 in hex. A plain JavaScript number would silently turn it into 9,007,199,254,740,992 (20000000000000 in hex); here BigInt keeps the last digit.
  6. Two's complement. -100 in 8 bits is 256 - 100 = 156 = 9C. -1 in 32 bits is FFFFFFFF. 200 does not fit in a signed 8-bit value (the range is -128 to 127), so the 8-bit row is hidden and the 16-bit row shows 00C8.

Common mistakes and limits

Ways to use the result

Frequently Asked Questions

Can this convert negative numbers or decimals?

Negative whole numbers work: put a - in front. The 8, 16, 32 and 64-bit two's complement forms are shown too. Numbers with a decimal point are not supported; only integers are handled.

Why does it go all the way up to base 36?

Base 36 uses all of 0 to 9 and A to Z (10 to 35), making it the largest base you can write with only digits and letters. It appears in URL shorteners and short ID schemes, so it is included.

Are very large numbers converted accurately?

Yes. Ordinary JavaScript numbers lose exactness past about 9 x 1015 (253), but this tool calculates with BigInt, so there is no built-in digit limit. Inputs of thousands of digits can make the browser slow.

Can I paste values that start with 0x or 0b?

Yes, in the matching field. 0x (hex), 0b (binary) and 0o (octal) are stripped automatically, and spaces and underscores are ignored, so 1111_0000 is fine.

Why does one hex digit equal four bits?

Because 16 = 24. A hex digit covers 0 to 15, which is exactly the 16 values four bits can hold. By the same reasoning an octal digit corresponds to three bits and a base-32 digit to five.

Why are some bit widths missing from the two's complement table?

A value is shown only for widths that can hold it. For example 200 is outside the signed 8-bit range of -128 to 127, so the table starts at 16 bits.

Related tools

This tool is for learning and development reference. For cryptographic or security-sensitive values, verify with an established library and the official specification.