Calculator
Example Data Table
| Example | A | B | Width | Operation | Binary Result | Decimal Result |
|---|---|---|---|---|---|---|
| 1 | 29 | 23 | 8 | A AND B | 0001 0101 | 21 |
| 2 | 29 | 23 | 8 | A OR B | 0001 1111 | 31 |
| 3 | 29 | 23 | 8 | A XOR B | 0000 1010 | 10 |
| 4 | 29 | – | 8 | NOT A | 1110 0010 | 226 |
| 5 | 29 | – | 8 | A Left Shift by 2 | 0111 0100 | 116 |
Formula Used
Bitwise calculations work on the binary representation of integers. Each operation is applied bit by bit, and the final value is trimmed by the selected bit width.
- AND: Result = A & B
- OR: Result = A | B
- XOR: Result = A ^ B
- NOT: Result = ~A or ~B, then masked to width
- NAND: Result = ~(A & B), then masked
- NOR: Result = ~(A | B), then masked
- XNOR: Result = ~(A ^ B), then masked
- Left Shift: Result = (Value << n) & Mask
- Right Shift: Result = (Value >> n) within the selected width
- Mask: Mask = 2w − 1, where w is the bit width
The mask keeps the answer inside the chosen width, which is useful when you want 8-bit, 16-bit, or 32-bit style outputs.
How to Use This Calculator
- Enter Input A and choose its base.
- Enter Input B and choose its base when your operation needs a second value.
- Select the bitwise operation you want to apply.
- Set the bit width to control masking and output length.
- Provide a shift count for shift operations.
- Press Calculate Bitwise Result to display the answer above the form.
- Review decimal, binary, octal, and hexadecimal outputs together.
- Use the CSV and PDF buttons to save the displayed result.
FAQs
1. What does a bitwise operation calculator do?
It applies operations such as AND, OR, XOR, NOT, and shifts directly to the binary form of integers. The tool also converts the final answer into decimal, binary, octal, and hexadecimal formats.
2. Why does bit width matter?
Bit width controls how many bits remain after masking. This affects complements, shifts, and large numbers because extra bits outside the chosen width are removed from the displayed result.
3. Can I enter binary or hexadecimal values?
Yes. You can choose decimal, binary, octal, or hexadecimal for each input independently. The calculator reads the selected base, converts the value, and shows the result in multiple bases.
4. Why can NOT produce a large positive answer?
The calculator masks the inverted bits inside the chosen width. For example, NOT on an 8-bit value flips only eight bits, so the final number is shown as an unsigned width-limited result.
5. What is the difference between XOR and OR?
OR returns 1 when either bit is 1. XOR returns 1 only when the two bits differ. XOR is often used for toggling flags, parity checks, and difference detection.
6. How are shift operations handled here?
Left shifts move bits left and insert zeros from the right. Right shifts move bits right. The tool then applies the chosen mask so the result stays within the selected width.
7. Does the calculator support negative numbers?
Negative decimal inputs are accepted and then masked to the chosen width. Non-decimal entries should be supplied as unsigned values so the displayed conversions remain clear and consistent.
8. When should I export CSV or PDF results?
Use CSV when you want a structured data record for spreadsheets or logs. Use PDF when you want a neat report for sharing, printing, or attaching to documentation.