← Number system calculators

COMPUTER SCIENCE / NUMBER SYSTEMS

Bitwise Calculator for AND, OR, XOR, NOT, Shifts and Bit Rotations

Apply bit operations within a fixed 8, 16, 32 or 64-bit word, then inspect signed and unsigned results in binary, octal, decimal and hexadecimal.

Enter values and operation

In auto mode, use 0b for binary and 0x for hexadecimal. Shift and rotation counts are always nonnegative decimal integers.

How the bitwise operators work

AND produces 1 only when both aligned bits are 1. OR produces 1 when either bit is 1. XOR produces 1 when the bits differ. NOT reverses every bit, so its result depends on the selected word width.

ABANDORXOR
00000
01011
10011
11110

Why word width and signed interpretation matter

A fixed-width register has only a set number of positions. This calculator discards overflow beyond that width. The same pattern can be read as unsigned or as signed two’s complement: for example, 11111111 is 255 unsigned but −1 signed in eight bits.

Shifts and rotations

A left shift inserts zeros at the right. A logical right shift inserts zeros at the left, while an arithmetic right shift repeats the sign bit. Rotation moves discarded bits around to the opposite end instead of losing them. A left shift is equivalent to multiplication by a power of two only when no significant bit overflows.

Practical bitwise use cases

Checking permissions and feature flags

Suppose READ = 4, WRITE = 2 and EXECUTE = 1. A permission value of 6 is binary 110. The expression 6 AND 4 returns 4, so READ is enabled; 6 AND 1 returns 0, so EXECUTE is not. OR can enable a flag and XOR can toggle it.

Extracting a colour channel

The packed colour 0xAC3C53 contains red, green and blue bytes. Shifting right by 16 and applying AND 0xFF extracts red as 0xAC, or 172 decimal. Similar masks decode packed dates, device registers and file headers.

Finding an IPv4 network address

A router combines an address with its subnet mask using AND. The last octet of 192.168.1.77 is 01001101 and the last octet of a /26 mask is 11000000. AND gives 01000000, or 64, making the network address 192.168.1.64.

Worked examples

Expression8-bit resultWhat it demonstrates
0xAC AND 0x3C0x2CKeeps only bits present in both masks
NOT 0xAC0x53Flips all eight bits
0xAC logical-right 20x2BInserts two zero bits
0xAC arithmetic-right 20xEBExtends the leading sign bit
rotate-left 0xAC by 10x59Returns the discarded high bit at the right

Frequently asked questions

What is the difference between logical and arithmetic right shift?

Logical shift inserts zeros. Arithmetic shift repeats the sign bit, preserving the sign of a two’s-complement value.

Why did a left shift lose some bits?

Bits that move beyond the selected word width overflow and are discarded. Choose a wider word to retain them.

Can I enter negative numbers?

Yes. Negative decimal values are wrapped into their two’s-complement representation at the chosen width.

How do I test whether bit n is set?

Create a mask by shifting 1 left by n positions, then AND it with the value. A nonzero result means that bit is set.

Why does NOT depend on the word width?

NOT flips every available position. NOT 5 is 250 in eight unsigned bits, but 65,530 in sixteen unsigned bits because the wider word contains eight additional leading zeros to flip.

Are bitwise operations the same as Boolean operators?

No. Bitwise operators process every bit of integer operands. Boolean operators combine true-or-false conditions and may short-circuit without evaluating the second condition.

Does right shift always divide by two?

Each one-bit right shift resembles integer division by two, but signed rounding and the choice between logical and arithmetic shift affect negative values.

← Number system calculators