Need to convert text to ASCII codes? This guide covers everything you need to know about text to ASCII conversion via API, including different output formats and encoding options.
What is Text to ASCII Encoding?
Text to ASCII conversion transforms readable text into its numeric ASCII code representation. Each character in the text is converted to its corresponding ASCII value (0-127 for standard ASCII).
Example: "Hello" becomes "72 101 108 108 111"
Output Formats
ASCII codes can be represented in different formats:
- Decimal: 72 101 108 108 111
- Hexadecimal: 48 65 6C 6C 6F
- Binary: 01001000 01100101 01101100 01101100 01101111
- Octal: 110 145 154 154 157
Using the Text to ASCII API
TinyFn provides a simple endpoint to convert text to ASCII:
POST https://api.tinyfn.io/v1/text/text-to-ascii
Headers: X-API-Key: your-api-key
Content-Type: application/json
{
"text": "Hello",
"format": "decimal",
"separator": " "
}
{
"ascii": "72 101 108 108 111",
"codes": [72, 101, 108, 108, 111],
"character_count": 5,
"format": "decimal"
}
Parameters
| Parameter | Type | Description |
|---|---|---|
text |
string | The text to convert (required) |
format |
string | Output format: decimal, hex, binary, octal (default: decimal) |
separator |
string | Separator between codes (default: space) |
Code Examples
JavaScript / Node.js
const response = await fetch(
'https://api.tinyfn.io/v1/text/text-to-ascii',
{
method: 'POST',
headers: {
'X-API-Key': 'your-api-key',
'Content-Type': 'application/json'
},
body: JSON.stringify({
text: 'Hello',
format: 'decimal'
})
}
);
const result = await response.json();
console.log(result.ascii); // "72 101 108 108 111"
Python
import requests
response = requests.post(
'https://api.tinyfn.io/v1/text/text-to-ascii',
headers={'X-API-Key': 'your-api-key'},
json={'text': 'Hello', 'format': 'decimal'}
)
result = response.json()
print(result['ascii']) # "72 101 108 108 111"
cURL
curl -X POST "https://api.tinyfn.io/v1/text/text-to-ascii" \
-H "X-API-Key: your-api-key" \
-H "Content-Type: application/json" \
-d '{"text": "Hello", "format": "decimal"}'
Common Use Cases
- Data Encoding: Encode text for transmission
- Educational Tools: Teach ASCII and encoding
- Debugging: Inspect text at byte level
- Puzzles & Games: Create encoding challenges
- Protocol Development: Work with ASCII-based protocols
Best Practices
- Choose format wisely: Decimal is human-readable, hex is compact
- Handle non-ASCII: Decide how to handle characters > 127
- Consistent separators: Use space or comma for readability
- Preserve original: Return both encoded and original text
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-text": {
"url": "https://api.tinyfn.io/mcp/text/",
"headers": {
"X-API-Key": "your-api-key"
}
}
}
}
See all text analysis tools available via MCP in our Text Analysis MCP Tools for AI Agents guide.
Try the Text to ASCII API
Get your free API key and start encoding text in seconds.
Get Free API Key