Number System Converter API

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.

Endpoint

POST https://www.promptbox.cn/api/hex.php

Request

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.

Example Request (Decimal Input)

{
  "decimal": "255"
}

Example Request (Hexadecimal Input)

{
  "hexadecimal": "FF"
}

Example Request (Binary Input)

{
  "binary": "11111111"
}

Response

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).

Example Response (Decimal Input)

{
  "decimal": "255",
  "hexadecimal": "FF",
  "binary": "1111 1111",
  "method": "decimal_input"
}

Example Response (Hexadecimal Input)

{
  "decimal": "255",
  "hexadecimal": "FF",
  "binary": "1111 1111",
  "method": "hexadecimal_input"
}

Example Response (Binary Input)

{
  "decimal": "255",
  "hexadecimal": "FF",
  "binary": "1111 1111",
  "method": "binary_input"
}

Error Handling

If invalid input is provided, the API responds with an error field in JSON.

Example Error (Invalid Hexadecimal)

{
  "error": "Invalid hexadecimal number."
}