Text to ASCII API: The Complete Guide

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
Note: Characters outside the ASCII range (like emojis or accented letters) will be converted to their Unicode code points or show an error.

Using the Text to ASCII API

TinyFn provides a simple endpoint to convert text to ASCII:

API Request
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": " "
}
Response
{
  "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

  1. Choose format wisely: Decimal is human-readable, hex is compact
  2. Handle non-ASCII: Decide how to handle characters > 127
  3. Consistent separators: Use space or comma for readability
  4. 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

Ready to try TinyFn?

Get your free API key and start building in minutes.

Get Free API Key