# Bitwise API
> Bit-level integer maths as an API, at 8-, 16-, 32- or 64-bit width with exact big-integer arithmetic. The inspect endpoint takes a number (decimal, 0x hex, 0b binary or 0o octal) and returns its decimal, signed (two's-complement), hexadecimal, binary and octal forms, plus the population count (Hamming weight), parity, leading and trailing zero counts, whether it is a power of two, its bit-reversed value and its byte-swapped (endianness) value. The ops endpoint performs a bitwise operation — AND, OR, XOR, NAND, NOR, XNOR, NOT, logical and arithmetic shifts (shl, shr, sar) and rotations (rol, ror) — masked to the chosen width. The bit endpoint sets, clears, toggles or tests an individual bit by index. Everything is computed locally and deterministically, so it is instant and private. Ideal for embedded and systems programming, network-protocol and flag handling, graphics and hashing, emulators and reverse engineering, and teaching binary. Pure local computation — no key, no third-party service, instant. Live, nothing stored. 4 endpoints. This is bit manipulation; for base 2-36 conversion use a base-convert API and for IEEE-754 floating-point bits use a floating-point API.

## Authentication
All requests require your oanor API key in the `x-oanor-key` header. Get one at https://www.oanor.com/developer/keys.

```bash
curl -H "x-oanor-key: oanor_live_…" "https://api.oanor.com/bitwise-api/..."
```

## Pricing
- **Free** (Free) — 7,135 calls/Mo, 2 req/s
- **Starter** ($9/Mo) — 16,650 calls/Mo, 8 req/s
- **Pro** ($29/Mo) — 217,500 calls/Mo, 20 req/s
- **Mega** ($67/Mo) — 1,130,000 calls/Mo, 50 req/s

## Endpoints

### Bitwise

#### `GET /v1/bit` — Set/clear/toggle/test a bit

**Parameters:**
- `value` (query, required, string) — Integer Example: `5`
- `index` (query, required, string) — Bit index 0..width-1 Example: `0`
- `action` (query, optional, string) — set|clear|toggle|test Example: `toggle`
- `width` (query, optional, string) — 8|16|32|64 Example: `8`

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/bitwise-api/v1/bit?value=5&index=0&action=toggle&width=8"
```

**Response:**
```json
{
    "data": {
        "index": 0,
        "action": "toggle",
        "result": {
            "hex": "0x04",
            "octal": "0o4",
            "width": 8,
            "binary": "00000100",
            "decimal": "4",
            "signed_decimal": "4"
        },
        "bit_value": 1
    },
    "meta": {
        "timestamp": "2026-06-03T17:42:10.055Z",
        "request_id": "6b56a959-2bcf-4de7-820d-be21c90ca1c8"
    },
    "status": "ok",
    "message": "Bit",
    "success": true
}
```

#### `GET /v1/inspect` — Inspect an integer at a bit width

**Parameters:**
- `value` (query, required, string) — Integer (dec, 0x, 0b, 0o) Example: `255`
- `width` (query, optional, string) — 8|16|32|64 (default 32) Example: `8`

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/bitwise-api/v1/inspect?value=255&width=8"
```

**Response:**
```json
{
    "data": {
        "hex": "0xff",
        "octal": "0o377",
        "width": 8,
        "binary": "11111111",
        "parity": "even",
        "decimal": "255",
        "byte_swapped": "0xff",
        "leading_zeros": 0,
        "reversed_bits": "0xff",
        "signed_decimal": "-1",
        "trailing_zeros": 0,
        "is_power_of_two": false,
        "population_count": 8
    },
    "meta": {
        "timestamp": "2026-06-03T17:42:10.156Z",
        "request_id": "a26c9408-7c56-4ddd-b777-b6e75269242e"
    },
    "status": "ok",
    "message": "Inspect",
    "success": true
}
```

#### `GET /v1/ops` — Bitwise operation

**Parameters:**
- `a` (query, required, string) — Operand Example: `5`
- `b` (query, optional, string) — Second operand / shift amount Example: `3`
- `op` (query, required, string) — and|or|xor|nand|nor|xnor|not|shl|shr|sar|rol|ror Example: `xor`
- `width` (query, optional, string) — 8|16|32|64 Example: `32`

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/bitwise-api/v1/ops?a=5&b=3&op=xor&width=32"
```

**Response:**
```json
{
    "data": {
        "a": "0x00000005",
        "b": "0x00000003",
        "op": "xor",
        "width": 32,
        "result": {
            "hex": "0x00000006",
            "octal": "0o6",
            "width": 32,
            "binary": "00000000000000000000000000000110",
            "decimal": "6",
            "signed_decimal": "6"
        }
    },
    "meta": {
        "timestamp": "2026-06-03T17:42:10.235Z",
        "request_id": "3d743af0-c18a-4162-9cd0-dc2d869f86a1"
    },
    "status": "ok",
    "message": "Bitwise op",
    "success": true
}
```

### Meta

#### `GET /v1/meta` — Spec

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/bitwise-api/v1/meta"
```

**Response:**
```json
{
    "data": {
        "name": "Bitwise API",
        "notes": "All operations are masked to the chosen width; negative inputs are folded by two's complement. shr is logical, sar is arithmetic. Nothing is stored.",
        "version": "v1",
        "endpoints": [
            {
                "path": "/v1/inspect",
                "params": {
                    "value": "an integer (dec, 0x, 0b, 0o)",
                    "width": "8|16|32|64 (default 32)"
                },
                "returns": "representations, popcount, parity, zero counts, reversed and byte-swapped"
            },
            {
                "path": "/v1/ops",
                "params": {
                    "a": "operand",
                    "b": "second operand (or shift/rotate amount)",
                    "op": "and|or|xor|nand|nor|xnor|not|shl|shr|sar|rol|ror",
                    "width": "8|16|32|64"
                },
                "returns": "the result in all representations"
            },
            {
                "path": "/v1/bit",
                "params": {
                    "index": "bit index 0..width-1",
                    "value": "an integer",
                    "width": "8|16|32|64",
                    "action": "set|clear|toggle|test"
                },
                "returns": "the bit value and the resulting integer"
            },
            {
                "path": "/v1/meta",
                "params": [],
                "returns": "this document"
        
…(truncated, see openapi.json for full schema)
```


---
Marketplace page: https://www.oanor.com/api/bitwise-api
OpenAPI spec: https://www.oanor.com/api/bitwise-api/openapi.json
