{
  "id": "base-converter",
  "version": "34f6eb7646fc",
  "status": "published",
  "name": "Base Converter",
  "question": "What is this number in another base?",
  "summary": "Converts a whole number from any base from 2 to 36 into any other base, exactly at any size, and shows it in decimal, binary, octal and hexadecimal.",
  "category": "logic",
  "subcategory": "binary",
  "url": "https://www.acalculator.org/logic/base-converter",
  "markdown": "https://www.acalculator.org/logic/base-converter.md",
  "kind": "function",
  "method": "Value = Σ dᵢ × fromⁱ over the digits, right to left from i = 0; then the value is divided by the new base again and again, and the remainders, read last to first, are the new digits.",
  "assumptions": [
    "Whole numbers only: a point or fraction part is not read.",
    "Digits above 9 are the letters A to Z (A = 10, Z = 35), in capitals or small letters.",
    "Exact at any size: the page works in whole-number arithmetic, never in floating point."
  ],
  "inputs": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "n": {
        "title": "Number",
        "description": "The whole number to convert, in its own base: the digits 0 to 9, then the letters A to Z for digits 10 to 35, with an optional minus sign.",
        "type": "string",
        "maxLength": 200
      },
      "from": {
        "title": "From base",
        "description": "The base the number is written in.",
        "type": "integer",
        "minimum": 2,
        "maximum": 36
      },
      "to": {
        "title": "To base",
        "description": "The base to write the number in.",
        "type": "integer",
        "minimum": 2,
        "maximum": 36
      }
    }
  },
  "outputs": {
    "result": {
      "label": "Number in the new base",
      "description": "The number written in the \"to\" base, letters in capitals.",
      "format": "text"
    },
    "decimal": {
      "label": "Decimal (base 10)",
      "description": "The number in base 10.",
      "format": "integer"
    },
    "binary": {
      "label": "Binary (base 2)",
      "description": "The number in base 2.",
      "format": "text"
    },
    "octal": {
      "label": "Octal (base 8)",
      "description": "The number in base 8.",
      "format": "text"
    },
    "hex": {
      "label": "Hexadecimal (base 16)",
      "description": "The number in base 16.",
      "format": "text"
    },
    "digits": {
      "label": "Digits in the new base",
      "description": "How many digits the number has in the \"to\" base, not counting a minus sign.",
      "format": "integer"
    }
  },
  "defaultAnswer": {
    "inputs": {
      "n": "255",
      "from": 10,
      "to": 2
    },
    "outputs": {
      "result": "11111111",
      "decimal": "255",
      "binary": "11111111",
      "octal": "377",
      "hex": "FF",
      "digits": 8
    },
    "text": "255 in base 10 is 11111111 in base 2."
  },
  "examples": [
    {
      "given": {
        "n": "255",
        "from": 10,
        "to": 2
      },
      "expect": {
        "result": "11111111",
        "decimal": 255,
        "octal": "377",
        "hex": "FF",
        "digits": 8
      },
      "source": "Wikipedia, \"Positional notation\" (a digit string dₖ…d₁d₀ in base b is Σ dᵢ × bⁱ), https://en.wikipedia.org/wiki/Positional_notation (retrieved 2026-10-05); hand calculation in content.mdx: 255 = 2⁸ − 1, eight ones"
    },
    {
      "given": {
        "n": "1A3",
        "from": 16,
        "to": 10
      },
      "expect": {
        "result": "419",
        "decimal": 419,
        "binary": "110100011"
      },
      "source": "Wikipedia, \"Positional notation\" (a digit string dₖ…d₁d₀ in base b is Σ dᵢ × bⁱ), https://en.wikipedia.org/wiki/Positional_notation (retrieved 2026-10-05); hand calculation in content.mdx: 1 × 256 + 10 × 16 + 3 = 419"
    },
    {
      "given": {
        "n": "2021",
        "from": 3,
        "to": 7
      },
      "expect": {
        "result": "115",
        "decimal": 61
      },
      "source": "Wikipedia, \"Positional notation\" (a digit string dₖ…d₁d₀ in base b is Σ dᵢ × bⁱ), https://en.wikipedia.org/wiki/Positional_notation (retrieved 2026-10-05); hand calculation in content.mdx: 2 × 27 + 0 × 9 + 2 × 3 + 1 = 61 = 1 × 49 + 1 × 7 + 5"
    },
    {
      "given": {
        "n": "-zz",
        "from": 36,
        "to": 10
      },
      "expect": {
        "result": "−1295",
        "decimal": -1295
      },
      "source": "Wikipedia, \"Positional notation\" (a digit string dₖ…d₁d₀ in base b is Σ dᵢ × bⁱ), https://en.wikipedia.org/wiki/Positional_notation (retrieved 2026-10-05); hand calculation in content.mdx: Z = 35, 35 × 36 + 35 = 1,295"
    }
  ],
  "sources": [
    "Wikipedia, \"Positional notation\": a digit string in base b has the value Σ dᵢ × bⁱ, and conversion by repeated division. https://en.wikipedia.org/wiki/Positional_notation (retrieved 2026-10-05)",
    "Wikipedia, \"Radix\": bases and the digits 0 to 9 and A to Z. https://en.wikipedia.org/wiki/Radix (retrieved 2026-10-05)"
  ],
  "related": [
    "binary",
    "hex",
    "twos-complement"
  ],
  "changelog": []
}
