{
  "schemaVersion": 1,
  "slug": "base-converter-calculator",
  "category": "math",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "259bcdee55de5ac03d51848704bf6743595f54daf38f56d5bdf59b884dbe7903",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/base-converter-calculator.json",
    "src/engine.js"
  ],
  "runtimeSource": "/sources/engine.txt",
  "runtimeHash": "5c888d8898afbdee36267bb9977829e1e2ac568f6677c8ee87469c139864645c",
  "scope": "The compute function records implemented equations, constants, lookup tables and custom rules. Inputs record defaults and allowed values; outputs record precision and units. Defaults are examples, not recommendations. General background references are not evidence for this specific algorithm.",
  "publishedFormula": {
    "formula": "n ← n × B + dᵢ (i = 1 … m); K = ⌊log_b n⌋ + 1; e_k = x mod b, x ← ⌊x ÷ b⌋ (k = 1 … K)",
    "vars": [
      [
        "dᵢ",
        "Source-base digit, 0 ≤ dᵢ < B"
      ],
      [
        "m",
        "Number of source digits"
      ],
      [
        "B",
        "Source base"
      ],
      [
        "n",
        "Decimal value"
      ],
      [
        "b",
        "Target base"
      ],
      [
        "K",
        "Number of target digits"
      ],
      [
        "x",
        "Value being converted; x ← n initially"
      ],
      [
        "e_k",
        "k-th target-base digit"
      ]
    ],
    "note": "Exact BigInt conversion for bases 2/8/10/16/36. A prefix 0x/0b/0o is accepted only with its matching source base. Invalid digits suppress results and show an error. Signs are preserved; zero renders as one digit."
  },
  "externalEvidence": {
    "reviewedAt": "2026-10-12",
    "sources": [
      {
        "name": "MDN — BigInt and positional representations",
        "url": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toString"
      }
    ],
    "referenceRole": "definition",
    "implementationHash": "259bcdee55de5ac03d51848704bf6743595f54daf38f56d5bdf59b884dbe7903",
    "basis": "n ← n × B + dᵢ (i = 1 … m); K = ⌊log_b n⌋ + 1; e_k = x mod b, x ← ⌊x ÷ b⌋ (k = 1 … K)",
    "limitations": "The references explain definitions and methods; any extra preset must be checked against the assumptions on this page."
  },
  "contract": {
    "compute": "const DIGITS='0123456789abcdefghijklmnopqrstuvwxyz'; let raw=String(value==null?'':value).trim().toLowerCase(); const base=Number(fromBase), fail='—'; if(!raw||raw.length>4098)return{decimal:null,binary:null,octal:null,hexadecimal:null,base36:null,__error:'inputError'}; let sign=1n;if(raw[0]==='-'){sign=-1n;raw=raw.slice(1)}else if(raw[0]==='+')raw=raw.slice(1); const prefix=/^0([box])/.exec(raw); if(prefix){const allowed={b:2,o:8,x:16}[prefix[1]];if(base!==allowed)return{decimal:null,binary:null,octal:null,hexadecimal:null,base36:null,__error:'inputError'};raw=raw.slice(2)} if(!raw)return{decimal:null,binary:null,octal:null,hexadecimal:null,base36:null,__error:'inputError'}; let n=0n;const B=BigInt(base);for(const ch of raw){const digit=DIGITS.indexOf(ch);if(digit<0||digit>=base)return{decimal:null,binary:null,octal:null,hexadecimal:null,base36:null,__error:'inputError'};n=n*B+BigInt(digit)}n*=sign;const to=(b)=>{if(n===0n)return'0';const neg=n<0n,x=neg?-n:n,bb=BigInt(b);let out='';for(let v=x;v>0n;v/=bb)out=DIGITS[Number(v%bb)]+out;return(neg?'-':'')+out};return{decimal:n.toString(),binary:to(2),octal:to(8),hexadecimal:to(16).toUpperCase(),base36:to(36)};",
    "inputs": [
      {
        "name": "value",
        "type": "text",
        "default": "255",
        "step": 1
      },
      {
        "name": "fromBase",
        "type": "select",
        "default": 10,
        "options": [
          {
            "value": 2
          },
          {
            "value": 8
          },
          {
            "value": 10
          },
          {
            "value": 16
          },
          {
            "value": 36
          }
        ]
      }
    ],
    "outputs": [
      {
        "name": "decimal",
        "precision": 0,
        "unit": "",
        "type": "text"
      },
      {
        "name": "binary",
        "precision": 0,
        "unit": "",
        "type": "text"
      },
      {
        "name": "octal",
        "precision": 0,
        "unit": "",
        "type": "text"
      },
      {
        "name": "hexadecimal",
        "precision": 0,
        "unit": "",
        "type": "text"
      },
      {
        "name": "base36",
        "precision": 0,
        "unit": "",
        "type": "text"
      }
    ],
    "interpret": null
  }
}
