Clever Quest Lab Tools

Number Base Converter

2026-10-17

Convert a whole number between decimal, binary, hexadecimal and octal at 8, 16, 32 or 64 bits, read the same bits as unsigned or as signed two's complement, flip single bits in a bit grid, and decode or build bitmasks from bit flags you name yourself.

Convert between bases

Bit width
Decimal field shows
Unsigned
Signed (two's complement)
Bits that are 1
16-bit range

Bit grid (16 bits)

Click or tap a bit to flip it between 0 and 1. With a keyboard, Tab into the grid, move with the arrow keys and press Space or Enter. Bit 0 is the rightmost bit; the small number on each bit is its position, and each group of four bits shows its hex digit.

Bits that are 1

Bit2n (decimal)Hex maskFlag name

Bitmask / bit flags decoder

Give bits names, for example 3 = IS_ADMIN, then decode a value into flag names or tick names to build a value. It works on the same number as the converter above.

Decimal, or 0x…, 0b…, 0o… for hex, binary, octal.
Flags that are set

Named bits – tick or untick to change the value

    Edit names and sets

    Write bit = NAME, for example 3 = IS_ADMIN (bits 0 to 63). Lines copied from code such as IS_ADMIN = 1 << 3 or IS_ADMIN = 0x08 work too, and so does pasted JSON. Lines starting with # or // are comments. Changes are saved automatically in this browser.

    Everything runs in your browser. Numbers, settings and flag sets are kept only in this browser's local storage; nothing is uploaded.

    How to use the number base converter

    1. Pick the bit width: 8, 16, 32 or 64 bits, the size of your integer (one byte is 8 bits).
    2. Type a whole number into any of the four fields. The other three update as you type. Spaces, underscores and the prefixes 0x, 0b and 0o are allowed. In the decimal field you can also write a power of two such as 2^63 or 2^32-1.
    3. Choose whether the decimal field shows the unsigned or the signed (two's complement) value. The result box always lists both readings.
    4. Flip single bits in the bit grid. The table under it lists every bit that is 1 with its weight 2n and its hex mask.
    5. In the bit flags section, pick or write a set of names, then decode a value or tick names to build one.

    How it works

    Every base uses positional notation. A number written in base b with the digits dk … d1 d0 has the value

    value = dk × bk + … + d1 × b + d0

    Here b is the base (2, 8, 10 or 16), di is the digit in position i counted from the right starting at 0, and every digit is smaller than the base. Hexadecimal needs six extra digits, so A to F stand for 10 to 15. By hand, you convert a decimal number by dividing it by the base repeatedly and reading the remainders from last to first.

    Hex and octal are shorthand for binary. Because 16 = 24, one hex digit is exactly four bits (a nibble), and because 8 = 23, one octal digit is exactly three bits. That is why the bit grid shows a hex digit for every group of four bits.

    The tool stores the number as a pattern of exactly n bits, where n is the width, and calculates with arbitrary-precision integers, so 64-bit values stay exact. The same pattern p has two readings:

    unsigned = p
    signed = p − 2n if bit n−1 is 1, otherwise signed = p

    An n-bit unsigned number runs from 0 to 2n − 1, a signed one from −2n−1 to 2n−1 − 1. A negative decimal input is stored as p = value + 2n. If you switch to a smaller width and the number no longer fits, only the lowest n bits are kept and a note says so.

    Examples

    Example 1 – 255 at 8 bits. 255 ÷ 16 = 15 remainder 15, and 15 ÷ 16 = 0 remainder 15, so the hex digits are F and F: 0xFF. In binary that is 0b11111111, and in octal 3 × 64 + 7 × 8 + 7 = 255 gives 0o377. The top bit is 1, so the signed reading is 255 − 256 = −1.

    Example 2 – −1 at 16 bits. Choose 16-bit and Signed, then type −1. The stored pattern is −1 + 65,536 = 65,535, which is 0xFFFF: sixteen ones, octal 0o177777. It also works the other way: type FFFF in the hex field and the decimal field shows −1 (or 65,535 in Unsigned mode).

    Example 3 – 263 at 64 bits. Type 2^63 or 9223372036854775808. The hex field shows 8000 0000 0000 0000, binary is a 1 followed by 63 zeros, and octal is a 1 followed by 21 zeros, because 263 = 821. Only bit 63 is set, so the signed reading is 263 − 264 = −9,223,372,036,854,775,808, the smallest 64-bit signed integer.

    Example 4 – decoding flags. In the set “User permissions”, bit 0 is CAN_READ and bit 3 is IS_ADMIN. A user with both has the value 20 + 23 = 1 + 8 = 9, binary 1001, hex 0x0009 at 16 bits. Typing 9 into “Value to decode” shows CAN_READ | IS_ADMIN. In the file permission set, octal 0o755 = 7 × 64 + 5 × 8 + 5 = 493 decodes to seven names, from OTHERS_EXECUTE (bit 0) up to OWNER_READ (bit 8), because each octal digit is one read-write-execute group.

    Signed and unsigned: the same bits, two readings

    The bits never say whether they are signed. The program that reads them decides. At 8 bits:

    BitsHexUnsignedSigned
    0000 00000x0000
    0111 11110x7F127127
    1000 00000x80128−128
    1111 11110xFF255−1

    Common mistakes come from forgetting the width. 0xFF is −1 as a signed byte but 255 as a signed 16-bit number, because there it is 0x00FF and its top bit is 0. When a signed value moves to a wider type it is sign-extended: −1 at 8 bits (0xFF) becomes 0xFFFF at 16 bits, which is what the converter does when you widen in Signed mode.

    Bit flags and bitmasks

    A bit flag is a yes/no setting stored in one bit, so a single integer can hold up to 64 of them. The mask of flag number n is 1 << n, which equals 2n. Four bitwise operations cover almost everything you do with flags:

    Export a set as JSON or text to keep or share it, and import it later. The JSON format is {"name": "…", "flags": [{"bit": 0, "name": "CAN_READ"}]}; a plain object such as {"0": "CAN_READ", "3": "IS_ADMIN"} is also accepted. A line with more than one bit, such as BOTH = 0x03, is skipped with a message, because a flag needs exactly one bit.

    Frequently asked questions

    Why does the hex value have leading zeros?

    With “Leading zeros” ticked, binary and hex are padded to the full width, so you see all 16, 32 or 64 bits of the pattern. Untick it to show 0x1ED instead of 0x01ED. The value is the same.

    What do 0x, 0b and 0o mean?

    They are prefixes many programming languages use to mark hexadecimal, binary and octal literals. Older C-style code marks octal with a plain leading zero instead, so 0755 there means octal 755. This converter reads a plain leading zero in the decimal field as decimal.

    Why is 0xFFFF sometimes −1 and sometimes 65,535?

    Both are correct readings of the same sixteen ones. Unsigned it is 65,535; in two's complement the top bit counts as −32,768, which gives −1. The result box always shows both.

    Can I convert fractions or numbers longer than 64 bits?

    No. This tool handles whole numbers up to 64 bits. For binary fractions such as 0.1, and for widths other than 8, 16, 32 or 64, use the Two's Complement Calculator.

    How do I enter a negative number?

    Type it with a minus sign in the decimal field. Hex, binary and octal fields take a bit pattern, so for −1 at 16 bits you type FFFF there.

    Is anything I type sent to a server?

    No. All conversions run in your browser. Your numbers, settings and flag sets are stored only in this browser's local storage, and nothing is uploaded or shared.

    Related tools