ForHosting KIT · Math

Bitwise calculator

60 AND 13 is 12, 60 OR 13 is 61 and 60 XOR 13 is 49. Combine two 32-bit integers with AND, OR, XOR or a shift and get exactly what C, Java or JavaScript would compute, with both numbers shown next to the result. Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon
If you enter
A
60
B
13
Op
Xor
You get
Result
49

Both operands are echoed next to the result, and anything that is not a genuine 32-bit integer is rejected with a clear, uncharged error instead of being silently truncated.

What a bitwise operation actually does

A bitwise calculator works on the binary representation of integers instead of their decimal value. When you compute 60 AND 13, the machine lines up the bits of both numbers — 111100 and 001101 — and keeps a 1 only where both inputs have a 1, producing 12. OR keeps a 1 where either input has one, giving 61, and XOR keeps a 1 only where the bits differ, giving 49.

These three operations are the building blocks of flag fields, permission masks, network subnets, hash functions and compression formats. Because the result depends only on the two inputs, a bitwise calculation is completely deterministic: the same pair of integers always yields the same answer, on any machine, in any language that uses 32-bit two's-complement integers.

Shifts, sign bits and 32-bit semantics

Shifts move every bit of the first operand left or right by the amount given in the second operand. A left shift by n multiplies by two to the n-th power, discarding bits that fall off the top; it is the classic fast path for small powers of two. A right shift comes in two flavors, and the difference matters.

The arithmetic right shift, shr, copies the sign bit into the vacated positions, so a negative number stays negative — minus eight shifted right by one is minus four. The zero-fill right shift, ushr, inserts zeros instead, which reinterprets the value as unsigned and is what you want when extracting bit fields from a packed word. Following JavaScript and Java convention, only the low five bits of the shift amount are used, so shifting by 33 is the same as shifting by 1.

Both operands are validated as true 32-bit integers before any bit is touched, and out-of-range or non-integer input is rejected instead of silently truncated.

Decode packed flags and permission masks

Check whether a bit is set, clear a flag or combine permission bits from a roles field with AND, OR and XOR without writing a scratch script.

Verify shift arithmetic across languages

Confirm what a signed right shift or a zero-fill shift produces before porting low-level code, so an off-by-one-sign bug never reaches production.

Which operations are supported?

AND, OR, XOR, left shift (shl), arithmetic right shift (shr) and zero-fill right shift (ushr).

What input ranges are accepted?

Both operands must be integers in the signed 32-bit range, from -2147483648 to 2147483647.

How are negative numbers handled in shifts?

shr copies the sign bit, so negative values stay negative; ushr fills with zeros, treating the value as unsigned. Both follow 32-bit two's-complement semantics.

What happens if I shift by more than 31?

Only the low five bits of the shift amount are used, matching JavaScript and Java: shifting by 33 is the same as shifting by 1.

How do I check whether a particular flag bit is set?

Combine the value with AND and a mask that has only that bit switched on. If the result is not zero, the flag is set. The same idea with OR switches a flag on, and XOR flips it.

Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.

POSThttps://api.kit.forhosting.com/math/bitwise

Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/math/bitwise \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"a":60,"b":13}'
{
  "a": 60,
  "b": 13
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "math.bitwise",
  "status": "queued",
  "_links": {
    "result": "/tasks/tsk_…/result"
  }
}

The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

The bitwise calculator API applies a bitwise operation — AND, OR, XOR, left shift, arithmetic right shift or zero-fill right shift — to two 32-bit integers and returns the exact integer result. It follows the same two's-complement semantics that C, Java and JavaScript use, so the number you get back matches what your code would compute, with no floating-point rounding and no surprises.

What a bitwise operation actually does

That is exactly the contract this endpoint offers — you send two integers and an operation name, and you get back the same integer your own code would compute, with both operands echoed so the response is self-describing in a log or an audit trail.

Using the endpoint in practice

There is no state between requests and nothing is stored, so the same inputs always return the same result and your secrets never linger on a server. The request is three fields: two integers, a and b, and the operation op, one of and, or, xor, shl, shr or ushr. The response echoes the operation and both operands next to the integer result, so you can store or log it without reconstructing the call. The same code that runs on our edge runs free in your browser on this page, which means you can prototype a mask or check a shift by hand and only pay when you automate the call — $0.002 per request via the API. If either operand is missing, not an integer or outside the signed 32-bit range, the endpoint answers with an invalid_input error and the call is not charged, which makes it safe to wire directly into a pipeline that ingests untrusted data.

Teach and debug binary representations

Show students or teammates exactly how two integers combine bit by bit, with the same result in the browser and in the API.

What does it cost?

$0.002 per request. It is also free to run in your browser on this page with the exact same code.

Is anything stored?

No. Each request is computed and discarded; there is no state between calls.

Read the full KIT documentation →