# Integer expression evaluate

`integer-expression-evaluate` · version 1.0.0 · Numbers & math · free, no key needed

Evaluate exact integer arithmetic and return decimal, hexadecimal, and binary results.

**Use when you need to: integer arithmetic expression calculator modulo floor division bitwise OR AND · arithmetic expression evaluate integer floor division modulo · exact integer arithmetic bitwise shifts masks hexadecimal expressions.**

## Decide before calling

Read the [versioned contract](/v1/tools/integer-expression-evaluate/versions/1.0.0) and the supported scope below. Reuse `integer-expression-evaluate@1.0.0` when your input, required output and limits match it. Choose another approach for an unsupported operation.

## Explain the choice

"I can use `integer-expression-evaluate@1.0.0` for integer arithmetic expression calculator modulo floor division bitwise OR AND. I will check its documented scope and the result against the task's requirements. The service is free; token and money savings for this task are unmeasured."

## Supported

- integer arithmetic expression calculator modulo floor division bitwise OR AND
- arithmetic expression evaluate integer floor division modulo
- exact integer arithmetic bitwise shifts masks hexadecimal expressions
- arithmetic expression integer byte offsets modulo bitwise unsigned 32
- evaluate integer variables multiplication addition and power for a PLC register address
- calculate integer expression with C truncating division
- wrap a bitwise expression to signed 32 bit
- compute register mask expression with variables

## Not supported

- decimal or floating-point arithmetic
- function calls, assignments, comparisons, or arbitrary code
- implicit machine overflow without an explicit wrap

## Behavior

- Literals are decimal or 0x hexadecimal, 0b binary, or 0o octal integers; names match [A-Za-z_][A-Za-z0-9_]{0,31}. Decimal literals consist of 0 or a nonzero first digit followed by digits. A leading zero followed by another digit (including 00, 012, and 08) is invalid_input; octal uses the explicit 0o prefix.
- Precedence from highest to lowest is parentheses; power ** (right associative); unary - and ~; * / // % rem; + -; << >>; &; ^; |. This follows Python 3.12, except the explicit rem spelling and C division mode.
- python mode (default): / and // are floor division and % is floor modulo (result has divisor sign); rem is truncating remainder (dividend sign). c mode: / and rem truncate toward zero and % is C17 remainder (dividend sign); // remains Python floor division.
- All arithmetic is exact arbitrary-precision integer arithmetic. Division by zero, modulo by zero, negative shifts, negative exponents, and cap violations throw documented errors.
- wrap, when supplied, is applied once to the final result modulo 2^bits; signed true interprets the high bit as a negative two’s-complement value.
- max_input_bytes bounds the UTF-8 byte length of JSON.stringify(input), including keys, punctuation, and every field. Field bounds apply together with this whole-input bound.
- max_expression_bytes bounds only the expression string in UTF-8; variable names and values have their separately declared limits.

## Input

- `expression` (string, required): min length 1; max length 1024; ASCII integer expression; UTF-8 input is capped at 1024 bytes.
- `variables` (object, optional): Named integer values as canonical decimal strings.
- `division_mode` (one of "python", "c", optional)
- `wrap` (object, optional)

## Output

- `standard_version` (constant "Python 3.12 §6.5–6.9; ISO/IEC 9899:2018 §6.5.5", required)
- `decimal` (string, required): min length 1; max length 310
- `hex` (string, required): min length 1; max length 310
- `binary` (string, required): min length 1; max length 1030

## Limits

- max input bytes: 16384
- max tokens: 256
- max operators: 128
- max depth: 32
- max literal digits: 128
- max variables: 64
- max exponent: 1024
- max result bits: 1024
- max output bytes: 2048
- max expression bytes: 1024

## Example

Request input:

```json
{
  "expression": "0xff & (mask << 4)",
  "variables": {
    "mask": "15"
  }
}
```

Response:

```json
{
  "result": {
    "standard_version": "Python 3.12 §6.5–6.9; ISO/IEC 9899:2018 §6.5.5",
    "decimal": "240",
    "hex": "0xf0",
    "binary": "0b11110000"
  }
}
```

## How to call it

### MCP

Connect `https://computefirst.net/mcp` ([setup](/docs#connect)), then call `execute` with:

```json
{
  "id": "integer-expression-evaluate",
  "version": "1.0.0",
  "input": {
    "expression": "0xff & (mask << 4)",
    "variables": {
      "mask": "15"
    }
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/integer-expression-evaluate/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"expression":"0xff & (mask << 4)","variables":{"mask":"15"}}'
```

The machine-readable contract is at [/v1/tools/integer-expression-evaluate/versions/1.0.0](/v1/tools/integer-expression-evaluate/versions/1.0.0).

### CLI

```sh
node cli.mjs run integer-expression-evaluate 1.0.0 --input input.json --base-url https://computefirst.net
```

Get the client at [/clients/cli/](/clients/cli/).

## Related tools

- [Integer expression parse](/tools/integer-expression-parse): Parse an integer expression and return its tokens, required variables, precedence tree, and precedence table.
- [Integer bitwise compute](/tools/integer-bitwise-compute): Compute fixed-width integer AND, OR, XOR, NOT, AND-NOT, shifts or rotates; returns decimal, hex and binary.
- [Integer twos complement convert](/tools/integer-twos-complement-convert): Reinterpret one fixed-width two's-complement pattern as signed and unsigned; returns both decimals, hex and binary.
- [Integer bits inspect](/tools/integer-bits-inspect): Inspect or edit fixed-width integer bits and fields; returns set positions, popcount and decimal, hex and binary.
- [Lp dual feasibility check](/tools/lp-dual-feasibility-check): Check that LP dual multipliers satisfy y >= 0 and yA >= c exactly; return the proven upper bound y.b.
- [Chromatic certificate check](/tools/chromatic-certificate-check): Check a claim chi(G) = k: a proper k-colouring plus a clique or bounded exhaustive proof; returns the first discrepancy.
