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:
- Select Integer / Bitwise.
- Choose an 8-, 16-, 32-, or 64-bit width.
- Choose Signed or Unsigned.
- Enter a bitwise expression.
- Click Evaluate.
Supported Operators
| Operator | Description | Example |
|---|---|---|
& | Bitwise AND | 0b1100 & 0b1010 |
| | Bitwise OR | 0b1100 | 0b1010 |
xor | Bitwise XOR | 0b1100 xor 0b1010 |
~ | Bitwise NOT | ~0b1010 |
<< | Left shift | 5 << 3 |
>> | Right shift | 32 >> 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 & 0b1010Binary calculation:
1100
& 1010
------
1000Result:
8Bitwise OR
OR returns 1 when either operand contains 1 at that position.
Example:
0b1100 | 0b1010Binary calculation:
1100
| 1010
------
1110Result:
14Bitwise XOR
XOR returns 1 when the operand bits differ.
Example:
0b1100 xor 0b1010Binary calculation:
1100
^ 1010
------
0110Result:
6Alternatively:
xor(0b1100,0b1010)Bitwise NOT
NOT flips the bits within the selected width.
Example:
~0b00001111With an 8-bit width:
Input: 0000 1111
Output: 1111 0000Unsigned result:
240Signed result:
-16Left Shift
Left shift moves bits toward the most significant side.
Example:
5 << 3Result:
40Binary:
0000 0101becomes:
0010 1000Bits extending beyond the configured width are discarded by masking.
Right Shift
Right shift moves bits toward the least significant side.
Example:
32 >> 2Result:
8Signed 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 & 63nTherefore, 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/2Result:
3Signed division truncates toward zero.
Division by zero produces an error.
Integer Remainder
Use % to calculate the remainder.
Example:
17%5Result:
2Integer Functions
Integer mode supports:
| Function | Purpose |
|---|---|
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 & 0b00000100Result:
4The selected flag is set.
Set a Flag
0b10110000 | 0b00000100Result:
180Toggle a Flag
0b10110100 xor 0b00000100Result:
176Clear a Flag
0b11111111 & ~0b00000100In 8-bit mode:
251Best 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.
Updated 7 days ago
