The hex.php API allows you to convert between decimal, hexadecimal, and binary number systems.
It accepts JSON input and returns a structured JSON response containing all formats.
POST https://www.promptbox.cn/api/hex.php
Send a JSON payload with one of the following fields:
| Parameter | Type | Required | Description |
|---|---|---|---|
decimal |
string or integer | Optional* | Decimal number to convert. Accepts integers only. |
hexadecimal |
string | Optional* | Hexadecimal number (case-insensitive). Spaces are allowed. |
binary |
string | Optional* | Binary number consisting of 0 and 1. Spaces are allowed. |
*You must provide exactly one of the above fields per request.
{
"decimal": "255"
}
{
"hexadecimal": "FF"
}
{
"binary": "11111111"
}
The API returns a JSON object with all three number system representations and an indicator of the input method used.
| Field | Type | Description |
|---|---|---|
decimal |
string | Decimal representation of the input number, formatted with commas. |
hexadecimal |
string | Hexadecimal representation, uppercase, grouped in 4-character chunks. |
binary |
string | Binary representation, grouped in 4-digit chunks for readability. |
method |
string | Indicates which field was used for input (decimal_input, hexadecimal_input, or binary_input). |
{
"decimal": "255",
"hexadecimal": "FF",
"binary": "1111 1111",
"method": "decimal_input"
}
{
"decimal": "255",
"hexadecimal": "FF",
"binary": "1111 1111",
"method": "hexadecimal_input"
}
{
"decimal": "255",
"hexadecimal": "FF",
"binary": "1111 1111",
"method": "binary_input"
}
If invalid input is provided, the API responds with an error field in JSON.
{
"error": "Invalid hexadecimal number."
}