How to use it
- Type a number into Value, such as
255,0xff,-42or1010_1010. Spaces and underscores are ignored, and a leading-or+sets the sign. - Pick the base it’s written in: 2, 8, 10 or 16, or Other to type any base into Base, 2 to 36.
- Read The value in every base: Binary, Binary in fours, Octal, Decimal, Hex and Base 36, each with a Copy button.
- Under Two’s complement, pick 8 bits, 16 bits, 32 bits or 64 bits to see the value as a fixed-width bit pattern and what it reads as signed and unsigned. Off hides it.
If the value can’t be converted, a one-sentence error says why, and the table keeps the last value that did convert, so a half-typed number doesn’t blank the page.
Examples
A Unix file mode, 0o755, with 8:
Binary 111101101
Binary in fours 1_1110_1101
Octal 755
Decimal 493
Hex 1ed
Base 36 dp
Each octal digit is three bits, so 755 is 111 101 101: read, write and execute for the owner, read and execute for everyone else.
Four bytes from a hex dump, DE AD BE EF, with 16 and 32 bits:
Pattern 11011110101011011011111011101111
Pattern in fours 1101_1110_1010_1101_1011_1110_1110_1111
Pattern in hex deadbeef
Signed reading -559038737
Unsigned reading 3735928559
The top bit is 1, so a signed 32-bit integer such as Java’s int holds this pattern as a negative number.
A negative decimal, -1, with 10 and 32 bits: the base table shows -1 in every row, while Pattern in hex is ffffffff and Unsigned reading is 4294967295.
Inputs that don’t convert:
0xffwith 10:The 0x prefix means base 16, but the value is read in base 10.ffwith 10:"f" at position 1 isn't a digit in base 10.256with 10 and 8 bits:256 is above the unsigned 8-bit maximum, 255.
Good to know
- The base chip decides how the value is read.
10is ten with 10, two with 2 and sixteen with 16. A prefix is read in the base it names:0xwith 16,0owith 8,0bwith 2, in either case. Where its letter is a digit, it’s a digit:0bwith 16 is11. - A leading zero doesn’t mean octal. In C,
0755is an octal literal worth 493; here, with 10, it’s 755. Pick 8 for C-style octal. - Every value is exact, at any size. The tool uses arbitrary-precision integers, so
9007199254740993(2^53 + 1) converts digit for digit, while JavaScript’sNumber("9007199254740993")gives9007199254740992: an IEEE 754 double has 53 bits of precision. Input is limited to 2,048 characters. - Digits past 9 are letters,
afor ten up tozfor 35 in base 36. Input may use either case; output is lowercase. - Integers only.
1.5with 10 fails at position 2, like any character outside the base. Positions count digits only, not the sign, prefix or separators. - A width holds both readings. n bits hold signed values from -2^(n-1) to 2^(n-1) - 1 and unsigned values from 0 to 2^n - 1, so the tool accepts anything from the signed minimum to the unsigned maximum: -128 to 255 at 8 bits. A pattern whose top bit is 1 reads negative when signed:
0xffat 8 bits is-1signed,255unsigned.
Questions
How do I convert binary to decimal?
Pick 2, type the digits and read Decimal: 1011 is 11, since each digit is worth twice the one to its right (8 + 0 + 2 + 1). In code, parseInt('1011', 2) in JavaScript or int('1011', 2) in Python.
How do I convert hex to decimal?
Pick 16, type the hex with or without 0x, and read Decimal: ff is 255. In a shell, printf '%d\n' 0xff; in JavaScript, parseInt('ff', 16) is exact only up to 2^53, so use BigInt('0x' + hex) for 64-bit values.
How do I convert decimal to binary?
Pick 10, type the number and copy Binary: 255 is 11111111. In JavaScript, (255).toString(2); in Python, format(255, 'b'), or bin(255) for '0b11111111'.
How do I convert binary to hex?
Split the bits into fours from the right and write each group as one hex digit: 1101_1110 is de, because 1101 is 13 (d) and 1110 is 14 (e). With 2 picked, the Binary in fours and Hex rows show both.
How do I find the two’s complement of a negative number?
Add 2^n, where n is the width; that equals inverting every bit of the positive value and adding one. Type the number, pick a width under Two’s complement, and read Pattern and Pattern in hex: -1 at 32 bits is ffffffff.