Number Base Converter

Number Base Converter API

Development

Convert numbers between binary, octal, decimal, hexadecimal and any base from 2 to 36, with exact results for huge and negative numbers and a two's complement view.

Authentication

All API requests require a valid API key passed in the Authorization header as a Bearer token.

Rate Limit

120 requests per minute

Endpoints

1 endpoint available

Overview

Converts a whole number of any size between bases 2 and 36 using exact BigInt maths. Every response includes the number in binary, octal, decimal and hexadecimal. You can add one more target base and a two's complement view.

Input rules

  • value is a string, because large numbers do not fit in a JSON number.
  • It is read in fromBase (default 10). Digits above 9 are the letters a-z, in either case.
  • A leading + or -, a matching 0x, 0b or 0o prefix, and spaces, underscores, commas or apostrophes as digit separators are accepted.
  • Whole numbers only. Fractions are rejected. Up to 20,000 digits.

Output

  • binary, octal, decimal, hexadecimal: the number as strings, with a leading - when negative.
  • bitLength: number of binary digits in the absolute value (0 for zero).
  • toBase: present when you pass toBase.
  • twosComplement: present when you pass twosComplementBits. Values from -2^(n-1) to 2^n - 1 fit. When the value does not fit, you get fits: false with the allowed min and max.

Endpoints

POST
https://opentools.ca/api/v1/tools/number-base-converter
Convert a whole number between bases

Request Body

Content-Type: application/json

ParameterTypeRequiredDescription
value
string
Required
The number to convert, written in fromBase.
fromBase
number
OptionalBase of the input, an integer from 2 to 36.Default: 10
toBase
number
OptionalOne extra base to convert to, an integer from 2 to 36. Returned as toBase.
uppercase
boolean
OptionalUse capital letters for digits above 9 in the hexadecimal and toBase results.Default: false
group
boolean
OptionalGroup digits for readability: 4 for binary and hex, 3 for octal, and commas for decimal.Default: false
twosComplementBits
number
Enum: 8, 16, 32, 64
OptionalAdd a two's complement view at this bit width.

Response Example

{
  "success": true,
  "input": "255",
  "fromBase": 10,
  "binary": "11111111",
  "octal": "377",
  "decimal": "255",
  "hexadecimal": "ff",
  "bitLength": 8,
  "toBase": {
    "base": 36,
    "value": "73"
  },
  "twosComplement": {
    "bits": 8,
    "fits": true,
    "binary": "11111111",
    "hexadecimal": "ff",
    "signed": "-1",
    "unsigned": "255"
  }
}

Error Codes

400
Bad Request - Empty value, a digit that is not valid in fromBase, a fraction, or a base or width out of range
401
Unauthorized - Invalid or missing API key
403
Forbidden - API key is inactive or expired, or the request IP is not allowed for this key
429
Too Many Requests - Rate limit exceeded
500
Internal Server Error

Code Examples

curl -X POST https://opentools.ca/api/v1/tools/number-base-converter   -H "Authorization: Bearer YOUR_API_KEY"   -H "Content-Type: application/json"   -d '{
    "value": "255",
    "fromBase": 10,
    "toBase": 36,
    "twosComplementBits": 8
  }'

Ready to get started?

Create an API key to start using the Number Base Converter API.

Rather use it in your browser? Open the Number Base Converter