Bitwise NAND calculator
12 NAND 10 at 8 bits is 247, binary 11110111 and hex f7, after an intermediate AND of 8. Choose a width from 1 to 53 bits and see each step in decimal, zero-padded binary and hex, the way a fixed-width bus behaves. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- A
- 12
- B
- 10
- Width
- 8
- Result
- 247
- A masked
- 12
- B masked
- 10
- And result
- 8
Bitwise NAND, the inverted AND of two integers, is the universal digital-logic gate that outputs zero only when both input bits are one. Students verifying gate truth tables, embedded engineers checking mask-and-invert bus logic, and reverse engineers reconstructing firmware bit-ops all need a deterministic way to see what twelve NAND ten equals at eight bits in decimal, binary, and hex without opening a language REPL that silently truncates to thirty-two bits. This bitwise NAND calculator accepts two safe integers and a bit width from one to fifty-three, masks each operand to the low width bits, applies mathematical NAND as the complement of the AND under that mask, and returns the unsigned result with zero-padded binary and hexadecimal renderings plus the intermediate AND so you can audit each stage.
What bitwise NAND means and why width matters
The NAND of two bits is false only when both bits are true: zero NAND zero is one, zero NAND one is one, one NAND zero is one, and one NAND one is zero. That truth table is exactly the inverted AND, so a multi-bit NAND is the bit-wise complement of the AND of the two words.
In programming languages there is rarely a dedicated NAND operator; you write not of a and b, but language bitwise operators often use fixed machine widths and sign-extending arithmetic that diverge from a clean unsigned bus model. This calculator therefore takes an explicit width w from one through fifty-three, forms the mask of w ones, masks each operand to those low bits, computes the AND under the mask, then inverts and re-masks so the result is always an unsigned w-bit value.
That fixed-width contract matches how HDL and schematic tools think about a bus: only the active lanes exist. Binary fields are zero-padded to w so column alignment matches hand-drawn truth tables, and hex fields show the same unsigned magnitude for quick register-dump comparison. Negatives are accepted as safe integers; only their low w bits participate, matching two's-complement truncation into an unsigned field of width w rather than inventing infinite leading ones outside the bus.
Where a bitwise NAND calculator earns its keep
Digital design and FPGA labs still ask students to build multi-bit NAND buses and prove that cascading NAND gates implements AND, OR, and NOT; a live calculator that reports decimal, binary, and hex at a chosen width lets them check homework without drawing every column by hand.
Embedded firmware often implements inverted mask checks—enable a peripheral only when a bit is clear—by coding not of status and mask, which is exactly NAND on the relevant field; verifying those expressions at eight or sixteen bits catches off-by-one mask mistakes before they hit silicon. Computer-architecture courses introduce the Sheffer stroke and functional completeness; showing that a NAND b equals not of a and b at the same width grounds the theory in numbers students can recompute.
Security write-ups that reverse bit-twiddling in unpackers sometimes recover inverted conjunctions rather than plain AND; having a deterministic oracle that never silently uses thirty-two-bit sign extension avoids the classic language-port trap.
What you can do with it
Gate-level and HDL homework checks
Verify multi-bit NAND bus results at 4, 8, or 16 bits against hand-drawn truth tables and student HDL testbenches using matching binary columns.
Firmware inverted mask logic
Confirm not of status and mask for enable-when-clear register patterns, and document fixed-width field layouts in driver notes.
FAQ
How do I compute the bitwise NAND of two integers?
Send safe integers a and b plus width (1–53).
What is the truth table for NAND?
0 NAND 0 = 1, 0 NAND 1 = 1, 1 NAND 0 = 1, 1 NAND 1 = 0. Each result bit is 0 only where both operands have 1; that is inverted AND.
Why do I need a bit width?
NAND is NOT of AND; without a fixed width the complement of an integer is infinite ones in two's complement. Width w defines the bus: only the low w bits are kept after invert.
How are negative operands handled?
Negatives are valid safe integers; only their low width bits (two's-complement truncation into an unsigned w-bit field) participate in the AND and NAND.
Why is NAND called a universal gate?
Because any logic function can be built from NAND gates alone: chaining them gives you NOT, AND and OR. That is why textbooks and chip libraries treat NAND as a basic building block, and why digital design labs ask students to prove it.
Related tools
For developers — API access
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.
API endpoint
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.
Call it from your stack
curl -X POST https://api.kit.forhosting.com/dev/bitwise-nand \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"a":12,"b":10,"width":8}'const res = await fetch("https://api.kit.forhosting.com/dev/bitwise-nand", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"a": 12,
"b": 10,
"width": 8
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/dev/bitwise-nand",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"a": 12,
"b": 10,
"width": 8
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/dev/bitwise-nand", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"a":12,"b":10,"width":8}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"a":12,"b":10,"width":8}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/dev/bitwise-nand", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"a": 12,
"b": 10,
"width": 8
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "dev.bitwise_nand",
"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.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |
Technical notes
Failed validation is not billed; every successful call costs the published $0.002 base price.
What bitwise NAND means and why width matters
In digital logic a single NAND gate is universal: any boolean function can be built from NAND alone, which is why textbooks and silicon libraries treat it as a primitive.
Input contract, response shape, and error behaviour
Width must be an integer from one to fifty-three inclusive so the full ones mask stays inside the safe integer range. Example: a equals twelve, b equals ten, width equals eight yields masked values twelve and ten, AND equal to eight, and NAND equal to two hundred forty-seven because binary zero-zero-zero-zero-one-one-zero-zero AND zero-zero-zero-zero-one-zero-one-zero is zero-zero-zero-zero-one-zero-zero-zero, inverted and masked to eight bits is one-one-one-one-zero-one-one-one. POST a JSON body with three required integer fields: a and b as the operands, and width as the bit count. Each of a and b may arrive as a JSON number or as a numeric string in decimal, or with a zero-x, zero-b, or zero-o prefix for hex, binary, or octal. Values must be finite safe integers within plus or minus Number.MAX_SAFE_INTEGER; fractional numbers, Infinity, NaN, empty strings, and missing fields fail with invalid_input naming the field, and those failures are not billed. Optional aliases x or left or first map to a, y or right or second map to b, and bits or bit_width or nbits or w map to width. On success the body echoes a, b, and width, returns a_masked and b_masked as the low-width slices, and_result as the masked AND, and result as the NAND value. It also provides a_binary, b_binary, and result_binary with a zero-b prefix and zero padding to width, plus a_hex, b_hex, and result_hex with a zero-x prefix, a short operation string such as twelve NAND ten at eight-bit equals two hundred forty-seven, and a formula restating result equals not of a and b masked to width.
Integration use cases
CI fixtures for language-agnostic bit ops
Generate expected NAND vectors in decimal, binary, and hex so unit tests agree across languages that disagree on 32-bit bitwise width.
Technical questions
What does the bitwise NAND calculator cost?
The browser tool is free. API requests use prepaid KIT balance at $0.002 per successful call; invalid input is not billed.