Bitwise Operations

Radix Quest provides programmer-oriented bitwise calculations through Integer / Bitwise mode. Bitwise operators manipulate the binary representation of integers.

Enable Bitwise Mode

In the Calculator tab:

  1. Select Integer / Bitwise.
  2. Choose an 8-, 16-, 32-, or 64-bit width.
  3. Choose Signed or Unsigned.
  4. Enter a bitwise expression.
  5. Click Evaluate.

Supported Operators

OperatorDescriptionExample
&Bitwise AND0b1100 & 0b1010
|Bitwise OR0b1100 | 0b1010
xorBitwise XOR0b1100 xor 0b1010
~Bitwise NOT~0b1010
<<Left shift5 << 3
>>Right shift32 >> 2

The xor(a,b) function is also supported.

Bitwise AND

AND returns 1 for a bit only when both operands contain 1 at that position.

Example:

0b1100 & 0b1010

Binary calculation:

  1100
& 1010
------
  1000

Result:

8

Bitwise OR

OR returns 1 when either operand contains 1 at that position.

Example:

0b1100 | 0b1010

Binary calculation:

  1100
| 1010
------
  1110

Result:

14

Bitwise XOR

XOR returns 1 when the operand bits differ.

Example:

0b1100 xor 0b1010

Binary calculation:

  1100
^ 1010
------
  0110

Result:

6

Alternatively:

xor(0b1100,0b1010)

Bitwise NOT

NOT flips the bits within the selected width.

Example:

~0b00001111

With an 8-bit width:

Input:  0000 1111
Output: 1111 0000

Unsigned result:

240

Signed result:

-16

Left Shift

Left shift moves bits toward the most significant side.

Example:

5 << 3

Result:

40

Binary:

0000 0101

becomes:

0010 1000

Bits extending beyond the configured width are discarded by masking.

Right Shift

Right shift moves bits toward the least significant side.

Example:

32 >> 2

Result:

8

Signed Right Shift

With Signed enabled, the implementation interprets the operand as a signed integer before shifting.

This produces an arithmetic right shift, preserving the sign.

Unsigned Right Shift

With Signed disabled, the implementation shifts the unsigned value.

This behaves as a logical right shift.

Shift Count Limitation

The implementation masks shift counts using:

count & 63n

Therefore, the effective shift count is restricted to values from 0 through 63.

For example, a shift count of 64 is treated as zero.

This applies even when the selected integer width is 8, 16, or 32 bits.

Integer Division

Integer mode uses truncating integer division.

Example:

7/2

Result:

3

Signed division truncates toward zero.

Division by zero produces an error.

Integer Remainder

Use % to calculate the remainder.

Example:

17%5

Result:

2

Integer Functions

Integer mode supports:

FunctionPurpose
xor(a,b)Bitwise XOR
abs(x)Absolute value
min(...)Minimum
max(...)Maximum

Other floating-point mathematical functions are unavailable in integer mode.

Signedness Caveat

The integer implementations of min() and max() compare masked unsigned values, even when Signed is enabled.

This can produce unexpected results when working with negative two's-complement values.

Bit Mask Examples

Test a Flag

0b10110100 & 0b00000100

Result:

4

The selected flag is set.

Set a Flag

0b10110000 | 0b00000100

Result:

180

Toggle a Flag

0b10110100 xor 0b00000100

Result:

176

Clear a Flag

0b11111111 & ~0b00000100

In 8-bit mode:

251

Best Practices

  • Select the intended bit width before evaluating.
  • Use explicit binary or hexadecimal prefixes.
  • Review Signed when interpreting high-order bits.
  • Use Show all bases to inspect representations.
  • Remember that overflow wraps at the configured width.
  • Check shift counts carefully.

Note: Radix Quest is suitable for interactive bitwise exploration, but it is not a substitute for language-specific integer semantics when exact behavior depends on a particular CPU, compiler, or programming language.


Did this page help you?