Home › Developer & IT › Bitwise Operations Calculator
Bitwise Operations Calculator
Applies AND, OR, XOR, NOT, left shift, logical right shift or arithmetic right shift to integers of a chosen width (8, 16 or 32 bits) and reports the result as signed two's complement, unsigned, binary and hexadecimal.
When to use
You need the exact bit pattern of a masked, combined or shifted integer as a CPU register of a given width would hold it, including the signed and unsigned readings of the result.
Do not use when: Values exceed 32 bits (use arbitrary-precision arithmetic), you only need a base change (use base-converter), or you want floating-point bit layouts (use ieee-754-float).
Formula
ua = a mod 2^w; ub = b mod 2^w; and/or/xor/not applied bit by bit; shift_left = (ua·2^b) mod 2^w; shift_right_logical = floor(ua / 2^b); shift_right_arithmetic = floor(sa / 2^b) with sa the signed reading; result_signed = result_unsigned − 2^w when result_unsigned ≥ 2^(w−1)
Operands must fit the width either as signed (−2^(w−1) … 2^(w−1)−1) or unsigned (0 … 2^w−1) integers; shift counts must be 0 … w−1 as in C. All arithmetic is done with JavaScript 32-bit integer operators and masked to the width.
Inputs
| Parameter | Type | Unit | Required | Description |
|---|---|---|---|---|
a | integer | yes | Integer operand; negative values are interpreted in two's complement of the chosen width. Range: ≥ -2147483648, ≤ 4294967295 | |
b | integer | default 0 | Second operand for and/or/xor; the number of bit positions for shifts; ignored for not. Range: ≥ -2147483648, ≤ 4294967295 | |
operation | enum: and | or | xor | not | shift_left | shift_right_logical | shift_right_arithmetic | yes | Bitwise operation to apply. | |
bit_width | enum: 8 | 16 | 32 | default 32 | Register width; results are truncated to this many bits and read as two's complement for the signed value. |
Outputs
| Output | Type | Unit | Description |
|---|---|---|---|
result_signed | integer | Result read as a two's-complement signed integer of the chosen width. | |
result_unsigned | integer | Result read as an unsigned integer of the chosen width. | |
result_binary | string | Result zero-padded to the bit width. | |
result_hex | string | Result in hexadecimal, zero-padded to width/4 digits. | |
a_binary | string | First operand in two's complement at the chosen width. | |
b_binary | string | Second operand (or shift count) in two's complement at the chosen width. | |
expression | string | The evaluated expression in C-style notation. |
Example
12 AND 10 (32-bit): {"a":12,"b":10,"operation":"and","bit_width":"32"} → {"result_signed":8,"result_unsigned":8,"result_binary":"00000000000000000000000000001000","result_hex":"0x00000008","a_binary":"00000000000000000000000000001100"}
NOT 5 (8-bit): {"a":5,"operation":"not","bit_width":"8"} → {"result_unsigned":250,"result_signed":-6,"result_binary":"11111010","result_hex":"0xFA"}
GET https://tttkmbb.com/api/v1/calculate/bitwise-operations?a=12&b=10&operation=and&bit_width=32
Machine access
- API:
GET https://tttkmbb.com/api/v1/calculate/bitwise-operations(query parameters) orPOSTwith a JSON body{"inputs": {...}} - Schema: https://tttkmbb.com/api/v1/calculators/bitwise-operations · Markdown: https://tttkmbb.com/developer/bitwise-operations.md · JSON definition: https://tttkmbb.com/developer/bitwise-operations.json
- MCP: server
https://tttkmbb.com/mcp, toolrun_calculator with calculator_id="bitwise-operations" - OpenAPI operationId:
calculate_bitwise_operations - Freshness:
static. Authentication: none. Rate limit: fair use (see rate limits).
Sources
- Bitwise operation (Wikipedia) (reference)
- Two's complement (Wikipedia) (reference)
FAQ
Why are there two right shifts?
A logical shift fills the vacated high bits with zeros (unsigned division by 2^b); an arithmetic shift copies the sign bit, so negative numbers stay negative (signed division rounding toward −∞).
How is a negative operand handled?
It is converted to its two's-complement pattern at the chosen width, e.g. −1 becomes 11111111 in 8 bits (unsigned 255), before the operation is applied.
What if the shift count is larger than the width?
The calculator rejects it with OUT_OF_RANGE; in C such shifts are undefined behaviour, and JavaScript masks the count to 5 bits.
Related calculators
- Number Base Converter — Convert the operands or the result between binary, decimal and hexadecimal.
- IP Subnet Calculator — Subnet masking is a 32-bit AND/OR.
- IEEE 754 Floating-Point Converter — Bit layout of floating-point numbers.