Number Base Converter & Binary Calculator
Convert numbers between binary, octal, decimal, hexadecimal and any base from 2 to 36, then add, subtract, multiply, divide or shift them.
Common conversions
| Base | Value |
|---|---|
Binary Base 2 | — |
Octal Base 8 | — |
Decimal Base 10 | — |
Hexadecimal Base 16 | — |
Base 32 | — |
Arithmetic
Works on the input number above, with both numbers read in base 10.
Enter the input number above, then a second number.
Converts whole numbers between any bases from 2 to 36 — binary, octal, decimal and hexadecimal included — and shows the common conversions side by side. Numbers of any length convert exactly.
An Arithmetic section below does a sum on the number you entered: add, subtract, multiply, divide with a remainder, bitwise AND, OR and XOR, and shifts. It works in the input base, shows the result in binary, octal, decimal and hexadecimal, and writes addition and subtraction out in columns with the carries and borrows.
How to use it
Set the input base, type the number, and choose the output base. The table below always shows binary, octal, decimal, hexadecimal and base 32, each with a copy button.
- Uppercase output — letter digits as A–Z; on by default. Input may use either case.
- Ignore spaces and underscores — accepts
1111 0000or1_000_000; on by default. - Group digits — spaces the output in groups of four (three for octal and decimal) for readability.
The input is a whole number, with an optional - or + sign; a negative number converts to a minus sign and the digits of its size. In bases 2, 8 and 16 the prefixes 0b, 0o and 0x are accepted; a prefix for another base names the base to switch to. Decimal points are not read. Share gives a link that opens the same number, bases and sum, and the tool remembers them on this device.
Arithmetic takes the input number as its first number, an operator, and a second number typed in the input base, with the same prefixes and separators. Both numbers may have up to 2,000 digits. Nothing is calculated until both are valid.
- + − × — exact, with no rounding. Negative numbers are signed values: −5 + 3 is −2 in every base.
- ÷ — a quotient and a remainder, in two tables. The quotient rounds toward zero and the remainder takes the sign of the first number, so −17 ÷ 5 is −3 remainder −2. Dividing by 0 is an error: “Cannot divide by 0”.
- AND, OR, XOR — compare the two numbers bit by bit. They work on numbers of 0 or more only: “Bitwise operations take numbers of 0 or more”, because a negative number has no bits until a width such as 32 or 64 is chosen. The tool does not choose one.
- << and >> — move the first number left or right by the second number of bits, which is read in the input base like the other numbers, and is limited to 4,096. A left shift multiplies by a power of 2 and a right shift divides by one, dropping the remainder.
The result is shown in binary, octal, decimal and hexadecimal, and first in the input base when that is none of these. For + and − the working below it writes the sum in columns, for numbers of up to 64 digits: grey 1s above a column are carried to the next, and in a subtraction the grey figures show a digit after borrowing. When the numbers are not both 0 or more, the working first reduces the sum to their sizes and says so.
How bases work
In base b, each digit counts b times as much as the one to its right. Bases above 10 use letters for digits beyond 9: A is 10, F is 15, Z is 35. Base 32 here is this positional numbering, with digits 0–9 and A–V; it is not the Base32 text encoding used for data.
Conversion and arithmetic use arbitrary-precision integers, so very long numbers — 128-bit IDs, large hashes — convert and combine without rounding, and a shift is not cut to 32 bits as it is in JavaScript's own operators.
Adding in columns works as in decimal, with the base in place of ten: add the digits and any carry, write the remainder after dividing by the base, and carry the quotient, which in addition is 0 or 1. Subtracting borrows one unit of the next column, worth the base, when the digit above is too small.
Examples
A 64-bit hex value
- Hexadecimal
- FFFFFFFFFFFFFFFF
- Decimal
- 18446744073709551615
Exact to the last digit — beyond the 16 significant digits a JavaScript number can hold.
Adding in binary
- Input base
- 2
- Input number
- 1011
- Operator
- +
- Second number
- 110
The result is 10001, which is 17 in decimal and 11 in hexadecimal. 3 carries are written above the columns.
Subtracting across zeros
- Input base
- 2
- Input number
- 10000
- Operator
- −
- Second number
- 1
The result is 1111, 15 in decimal. The units column has to borrow, and every 0 between it and the leading 1 lends and borrows in turn, so the borrow runs the whole way along. The working shows each column.
Dividing with a remainder
- Input base
- 2
- Input number
- 1101
- Operator
- ÷
- Second number
- 10
The quotient is 110 and the remainder 1: 13 ÷ 2 is 6 remainder 1.
Masking a value with AND
- Input base
- 16
- Input number
- FFAA
- Operator
- AND
- Second number
- 00FF
AND keeps a bit only where both numbers have it, so 00FF keeps the low byte and clears the rest: the result is AA, or 10101010 in binary.
A shift past 32 bits
- Input base
- 10
- Input number
- 1
- Operator
- <<
- Shift by
- 40
The result is 1099511627776, which is 2⁴⁰ and 10000000000 in hexadecimal. In JavaScript, 1 << 40 gives 256, because its shift counts wrap at 32; here the number simply grows.
Common values
| Decimal | Binary | Octal | Hexadecimal |
|---|---|---|---|
0 | 0 | 0 | 0 |
7 | 111 | 7 | 7 |
10 | 1010 | 12 | A |
15 | 1111 | 17 | F |
16 | 1 0000 | 20 | 10 |
100 | 110 0100 | 144 | 64 |
255 | 1111 1111 | 377 | FF |
1024 | 100 0000 0000 | 2000 | 400 |
65535 | 1111 1111 1111 1111 | 177777 | FFFF |
Frequently asked questions
1 << 11 shifts by three. To shift by a count written in decimal, set the input base to 10 and read the result from the table.See also
- Hash Generator — for hexadecimal hashes of text.
- Text to Binary Converter — for text as binary, hex or decimal bytes, in UTF-8.
- Roman Numeral Converter — for numbers in another system altogether.