Number Base Converter API: Convert Between Any Base

Need to convert binary to hexadecimal? Decimal to octal? The Number Base Converter API converts numbers between any bases from 2 to 36, supporting all common number systems used in programming and mathematics.

What are Number Bases?

A number base (or radix) determines how many unique digits are used to represent numbers. We typically use base 10 (decimal) in everyday life, but computers use base 2 (binary), and programmers often work with base 16 (hexadecimal).

The number 255 in decimal equals 11111111 in binary and FF in hexadecimal - all representing the same value.

Common Number Bases

Base Name Digits Used Common Use
2Binary0-1Computer hardware, bit operations
8Octal0-7Unix permissions, legacy systems
10Decimal0-9Human-readable numbers
16Hexadecimal0-9, A-FColors, memory addresses, MAC addresses
36Base360-9, A-ZURL shorteners, compact IDs
Programmer's Tip: Hexadecimal is popular because each hex digit represents exactly 4 binary digits, making conversions easy.

Using the Base Converter API

TinyFn provides a flexible endpoint for base conversion:

API Request
GET https://api.tinyfn.io/v1/math/base-convert?number=255&from=10&to=16
Headers: X-API-Key: your-api-key
Response
{
  "input": {
    "value": "255",
    "base": 10
  },
  "output": {
    "value": "FF",
    "base": 16
  },
  "decimal_value": 255,
  "all_formats": {
    "binary": "11111111",
    "octal": "377",
    "decimal": "255",
    "hexadecimal": "FF"
  }
}

Parameters

Parameter Type Description
number string The number to convert (required)
from integer Source base (2-36, default: 10)
to integer Target base (2-36, default: 16)
uppercase boolean Use uppercase letters A-Z (default: true)
include_all boolean Include common format conversions (default: true)

Code Examples

JavaScript / Node.js

const response = await fetch(
  'https://api.tinyfn.io/v1/math/base-convert?number=1010&from=2&to=10',
  { headers: { 'X-API-Key': 'your-api-key' } }
);
const data = await response.json();
console.log(`Binary 1010 = Decimal ${data.output.value}`); // 10

Python

import requests

response = requests.get(
    'https://api.tinyfn.io/v1/math/base-convert',
    headers={'X-API-Key': 'your-api-key'},
    params={'number': 'FF', 'from': 16, 'to': 2}
)
data = response.json()
print(f"Hex FF = Binary {data['output']['value']}")  # 11111111

cURL

curl "https://api.tinyfn.io/v1/math/base-convert?number=777&from=8&to=10" \
  -H "X-API-Key: your-api-key"

Common Use Cases

  • Color Conversion: Convert RGB values to hex color codes
  • Developer Tools: Debug memory addresses and binary data
  • Networking: Convert IP addresses and MAC addresses
  • ID Generation: Convert numbers to compact base36 strings
  • Educational: Teach number systems and base conversion

Best Practices

  1. Validate input: Ensure digits are valid for source base
  2. Handle case sensitivity: A-F and a-f are equivalent in hex
  3. Use appropriate bases: Hex for bytes, binary for bits
  4. Consider padding: Binary often needs leading zeros
  5. Test edge cases: Zero, negative numbers, maximum values

Use via MCP

Your AI agent can call this tool directly via Model Context Protocol — no HTTP code needed. Add TinyFn to Claude Desktop, Cursor, or any MCP client:

{
  "mcpServers": {
    "tinyfn-math": {
      "url": "https://api.tinyfn.io/mcp/math/",
      "headers": {
        "X-API-Key": "your-api-key"
      }
    }
  }
}

See all math tools available via MCP in our Math MCP Tools for AI Agents guide.

Try the Base Converter API

Get your free API key and start converting between number bases.

Get Free API Key

Ready to try TinyFn?

Get your free API key and start building in minutes.

Get Free API Key