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 |
|---|---|---|---|
| 2 | Binary | 0-1 | Computer hardware, bit operations |
| 8 | Octal | 0-7 | Unix permissions, legacy systems |
| 10 | Decimal | 0-9 | Human-readable numbers |
| 16 | Hexadecimal | 0-9, A-F | Colors, memory addresses, MAC addresses |
| 36 | Base36 | 0-9, A-Z | URL shorteners, compact IDs |
Using the Base Converter API
TinyFn provides a flexible endpoint for base conversion:
GET https://api.tinyfn.io/v1/math/base-convert?number=255&from=10&to=16
Headers: X-API-Key: your-api-key
{
"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
- Validate input: Ensure digits are valid for source base
- Handle case sensitivity: A-F and a-f are equivalent in hex
- Use appropriate bases: Hex for bytes, binary for bits
- Consider padding: Binary often needs leading zeros
- 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