Your country

Tools that support it use your country for local currency, number formats, units and paper size. Your choice is saved only in this browser.

Type a name or a two-letter code. Use the up and down arrow keys to move through the countries, Enter to choose one and Escape to close.

Programmer Calculator (Bitwise)

Bitwise maths at a real bit width — with overflow, endianness and every base at once.

Developer No upload Works offline Free, no sign-up

Expression and settings

Bit width
Integers are
Numbers without a prefix are

Write numbers as 255, 0xFF, 0o377, 0b1111_1111 or 'A'. Operators: + − * / % **, & | ^ ~, << >> >>> and the words and or xor not nand nor shl shr sar rol ror mod.

Try:

Result

Decimal · signed 32-bit —
HEX
DEC
DEC (unsigned)
OCT
BIN

Bits

Click a bit (or use the arrow keys and Space) to flip it.

Bytes & endianness

Next steps

About the Programmer Calculator (Bitwise)

A calculator for the integer maths that comes up in low-level code: masks, flags, shifts, rotates, two’s complement and byte order. Choose a bit width (8, 16, 32, 64 or 128) and whether integers are signed or unsigned, then type an expression such as 0xFF & 0x0F, 1 << 31 or rol(0x80000001, 4). The result appears as you type in hex, decimal (both interpretations), octal and binary.

Every operation is computed exactly and then wrapped to the chosen width, the way fixed-size machine integers behave — so 200 + 100 at 8 bits gives 44, and the page tells you that it overflowed and by how much. Click any bit in the bit grid to flip it, read the value as big- or little-endian bytes, or swap the byte order in one click. 64- and 128-bit values are exact: there is no rounding above 2^53 as with JavaScript numbers.

How to use it

  1. Pick the bit width and Signed or Unsigned. Choose which base numbers without a prefix are in (DEC, HEX, OCT or BIN). The prefixes 0x and 0o always work, and so does 0b — except in HEX mode, where 0b1010 is itself a hex number (the page points this out).
  2. Type a number or an expression. Use the operator buttons on a phone, or the word forms and, or, xor, not, shl, shr, sar, rol, ror, mod.
  3. Read the result in every base. A yellow note appears if any step overflowed the width, with the exact value it would have had.
  4. Click bits in the grid to set or clear them, and use Bytes & endianness to see the byte order, the value as ASCII, or as an IEEE 754 float (16, 32 and 64 bits).

Examples

Mask the low nibble
Input
0xFF & 0x0F   (8-bit)
Result
HEX 0F · DEC 15 · BIN 0000 1111
Setting the top bit of a signed 32-bit integer
Input
1 << 31   (signed 32-bit)
Result
DEC −2,147,483,648 · HEX 8000 0000
Overflow: 1 << 31 = 2,147,483,648 does not fit in signed 32-bit

In unsigned mode the same expression is 2,147,483,648 with no overflow.

Logical versus arithmetic right shift
Input
-16 >> 2   and   -16 >>> 2   (signed 32-bit)
Result
−4   and   1,073,741,820

>> copies the sign bit in; >>> shifts in zeros, exactly as in JavaScript and Java.

Swap endianness
Input
bswap(0x12345678)   (32-bit)
Result
0x78563412 — big-endian bytes 12 34 56 78 become 78 56 34 12

Common uses

  • Building and checking bit masks and flag fields for registers, permissions and protocol headers.
  • Converting between hex, decimal, octal and binary while reading a datasheet, a hex dump or a debugger.
  • Understanding two’s complement: why 0xFF is −1 as a signed byte, and what happens on overflow.
  • Checking shifts and rotates before writing them in C, Rust, Go, Java or JavaScript.
  • Turning a network-order (big-endian) value into a little-endian one, or reading bytes as a float.

Operators and their precedence

Operators bind as in C, tightest first:

  • ** power (right to left; -2 ** 2 is −4, as in Python)
  • unary -, +, ~ / not
  • *, / (whole-number division, rounding toward zero), % / mod (remainder, with the sign of the left side — like C and JavaScript)
  • +, -
  • << / shl, >>, >>> / shr, sar, rol, ror
  • & / and, nand
  • ^ / xor, xnor
  • | / or, nor

Use parentheses whenever you are unsure. Functions: rol(x, n), ror(x, n), bswap(x), bitrev(x), popcount(x), clz(x), ctz(x), bit(n), mask(n), abs(x), min(a, b), max(a, b). A character in single quotes is its code, so 'A' is 65.

Shifts: what this calculator does, and what languages do

<< multiplies by a power of two and drops the bits that leave the width (shown as an overflow when anything is lost). >> is an arithmetic shift in signed mode (the sign bit is copied in) and a logical one in unsigned mode. >>> and shr are always logical (zeros come in); sar is always arithmetic, even in unsigned mode, like the x86 instruction.

Shift counts here are taken literally: 1 << 40 at 32 bits is 0. Languages differ: JavaScript uses only the low 5 bits of the count for 32-bit operators, so 1 << 40 is 256 in JavaScript (ECMA-262, the shift operators), and in C and C++ shifting by the type’s width or more is undefined behaviour, as is overflow of signed arithmetic.

Two’s complement in one paragraph

A signed n-bit integer stores −x as the bit pattern of 2^n − x, which is the same as inverting every bit of x and adding 1 (~x + 1). That is why 0xFF is −1 as a signed byte and 255 as an unsigned one: the bits are identical, only the interpretation changes. The page always shows both decimal readings. Hex, octal and binary numbers that you type are read as bit patterns, so 0x80 at signed 8 bits is −128 without any overflow; a decimal 128 does not fit and wraps.

Limitations

  • Integers only: there is no decimal point. The float view only reinterprets the bits of the result as an IEEE 754 number.
  • One expression at a time; there are no variables or memory registers.
  • Widths are 8, 16, 32, 64 and 128 bits. Other widths (such as 24 or 12) can be imitated with mask(n) and &.
  • Results are exact, but the calculator is not a compiler: undefined behaviour in C or C++ (such as signed overflow) may be optimised differently by a real compiler.

Privacy

Everything happens in your browser. What you enter or open here is not uploaded or stored by MySmartCoPilot.

Frequently asked questions

How do I convert hex to decimal or binary?

Type the number with a 0x prefix (for example 0x7F), or switch “Numbers without a prefix are” to HEX and type 7F. The decimal, octal and binary forms appear at once; each has a Copy button.

Why does 0xFF show as −1?

Because the width is 8 bits and integers are signed: in two’s complement the pattern 1111 1111 means −1. Switch to Unsigned to read it as 255. Both readings are always listed under the result.

What is the difference between >> and >>>?

>> keeps the sign of a signed number by copying the top bit into the gap (arithmetic shift), so −16 >> 2 is −4. >>> always fills with zeros (logical shift), so the same bits shifted give a large positive number. In unsigned mode both give the same result.

What does a rotate do?

A rotate shifts the bits and puts the ones that fall off one end back in at the other, so nothing is lost: rol(0x80000001, 4) at 32 bits is 0x00000018. Rotates are common in hash functions and checksums.

Are 64-bit and 128-bit results exact?

Yes. The calculator uses arbitrary-precision integers (JavaScript BigInt) and wraps them to the width, so values such as 18,446,744,073,709,551,615 are exact — unlike ordinary JavaScript numbers, which lose precision above 2^53.

Is 0777 an octal number here?

No: with DEC selected, 0777 is the decimal number 777, and the page notes that C and C++ would read it as octal. Write 0o777 for octal (511). In HEX mode, 0b1010 is likewise the hex number 0xB1010; switch to DEC or BIN to use the 0b binary prefix.

What does the overflow note mean?

It means the exact mathematical result of a step did not fit in the chosen width and signedness, so only the low bits were kept — what a CPU register does. The note shows the exact value and the wrapped one, for every step that overflowed.

Quick answers and tool search

Type to search tools or to get a quick answer, for example 18% of 2500. Use the up and down arrow keys to move through the results, Enter to choose, and Escape to close.