RGB to decimal integer
Store a color as one whole number, or read one back: #FF8000 is 16744448. Red takes the high byte, green the middle and blue the low, the layout many engines and legacy themes expect. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- For to_int: hex colour
- #FF8000
- Conversion direction: to_int
- To int
- Resistance (Ω)
- 255
- G
- 128
- B
- 0
- Hex
- #FF8000
Many graphics APIs, game engines, and legacy UI toolkits store a colour as one 24-bit decimal integer instead of three separate channels or a hex string. The classic packing rule places red in the high byte, green in the middle byte, and blue in the low byte, so the integer equals red shifted left sixteen bits, bitwise-or green shifted left eight bits, bitwise-or blue. Values above 16777215 fail with a clear invalid input error so out-of-range integers never silently wrap.
Why a color can be one number
A color is usually written as three channels or as a hex code, but many game engines, binary asset formats and older interface toolkits keep it as a single 24-bit decimal number. That is compact to store and quick to compare, yet hard to read: 16744448 does not look like orange until it is unpacked. This converter works in both directions. Give it a six-digit hex code, with or without the hash, or red, green and blue values, and it returns the decimal. Give it a decimal and it returns the channels and the hex code, ready for artists, CSS variables or design tokens.
How the packing works, and common slips
The classic rule puts red in the high byte, green in the middle byte and blue in the low byte. In plain terms, red is moved sixteen bits to the left, green eight bits, and blue stays where it is; the three are then combined into one number. That is why #FF8000, with red 255, green 128 and blue 0, becomes 16744448. The largest possible value is 16777215, where every channel is full. A typical slip is a logged number that is too large, perhaps because it carries extra information: anything above 16777215 is rejected with a clear message instead of wrapping silently into a different color.
What you can do with it
Game engines and binary asset formats
Pack palette entries and debug colours into 24-bit integers that match engine APIs, then unpack logged values back to hex for artists.
Legacy UI and theme migration
Convert stored colour integers from older toolkits into hex and RGB channels for modern CSS variables and design tokens.
FAQ
What happens if the integer is above 16777215?
Only 24-bit values from 0 through 16777215 (0xFFFFFF) are accepted; larger integers are rejected and not charged.
Is the RGB to decimal integer converter free?
The browser tool runs free on your device.
Which hex formats are accepted?
Three- or six-digit hexadecimal with optional leading # or 0x, case-insensitive. You can also send rgb(r,g,b) or comma-separated channels 0–255.
What decimal number is #FF8000?
It is 16744448. Red 255 fills the high byte, green 128 the middle byte and blue 0 the low byte, and together they form one 24-bit whole number.
Can I turn a decimal back into a hex color?
Yes. Choose the reverse direction and enter a whole number from 0 to 16777215. You get the red, green and blue channels back, together with a normalized hex code.
Related tools
For developers — API access
Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.
API endpoint
Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.
Call it from your stack
curl -X POST https://api.kit.forhosting.com/color/rgb-int \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"color":"#FF8000","direction":"to_int"}'const res = await fetch("https://api.kit.forhosting.com/color/rgb-int", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"color": "#FF8000",
"direction": "to_int"
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/color/rgb-int",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"color": "#FF8000",
"direction": "to_int"
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/color/rgb-int", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"color":"#FF8000","direction":"to_int"}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"color":"#FF8000","direction":"to_int"}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/color/rgb-int", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"color": "#FF8000",
"direction": "to_int"
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "color.rgb_int",
"status": "queued",
"_links": {
"result": "/tasks/tsk_…/result"
}
}The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |
Technical notes
This capability converts either way: send a hex code or an RGB triple with direction to_int to obtain the decimal, or send a decimal in the legal 0 to 16777215 range with direction from_int to recover channels and a normalised hex code.
Packing RGB or hex into a 24-bit decimal integer
The required color field accepts the same shapes designers and developers type every day: a six-digit hex code with or without a leading hash such as #FF8000 or FF8000, a three-digit CSS shorthand such as #f80 which expands by doubling each digit, an optional 0x prefix for hex, a comma-separated triple like 255,128,0, or a CSS rgb function form such as rgb(255, 128, 0). Internally the engine multiplies red by sixty-five thousand five hundred thirty-six, multiplies green by two hundred fifty-six, and adds blue—equivalently the bit formula red shifted left sixteen bits, or green shifted left eight bits, or blue—yielding a unique integer between zero and sixteen million seven hundred seventy-seven thousand two hundred fifteen. Pure black packs to zero, pure white to the maximum, and brand oranges such as #FF8000 become one six seven four four four four eight. Choose direction to_int when you already have a colour and need a single packed number. Each channel must be an integer from zero to two hundred fifty-five inclusive; out-of-range channels and malformed hex lengths fail with invalid_input and are not charged. Aliases value, input, hex, n, and rgb map to the same color field when clients prefer those names. Direction aliases to_decimal, rgb_to_int, and encode select the same packing path so you can match vocabulary used in your codebase. Identical inputs always produce identical JSON because the path is pure arithmetic with no network, no random seed, and no wall clock.
Unpacking a decimal integer back to RGB and hex
The legal range is zero through sixteen million seven hundred seventy-seven thousand two hundred fifteen inclusive—the full 24-bit unsigned span. On success the engine extracts red as the value shifted right sixteen bits masked to eight bits, green as the value shifted right eight bits masked to eight bits, and blue as the low eight bits. Choose direction from_int when a pipeline hands you a packed colour integer and you need channels or a CSS-ready hex string. Place the integer in the color field as a decimal digit string or a JSON number, or as a 0x-prefixed hex literal. An integer above 16777215 is rejected with invalid_input that names the maximum so callers can fix the bug without guessing; negative integers are likewise rejected. The response echoes those channels as r, g, and b, nests them under an rgb object, builds a hash-prefixed six-digit uppercase hex field, exposes hex_digits without the hash, and supplies a css_rgb string such as rgb(255, 128, 0) for stylesheets. The same numeric value appears under decimal, integer, and rgb_int so UI code, SDK demos, and graders can pick whichever name fits without remapping. The method label is int_to_rgb for unpack and rgb_to_int for pack, and max is always 16777215 for documentation in clients. Direction aliases from_decimal, int_to_rgb, and decode select the unpack path.
API usage, pricing, workflows, and practical limits
Call the free in-browser RGB to decimal integer converter for design checks, game-tool demos, and quick mental verification without installing colour libraries. Authors shipping SDKs can map decimal and hex fields directly into forms that show a swatch beside the integer—the same mental model artists see when a binary file stores colours as 24-bit packed RGB. Keep integers inside the published 24-bit range; wider colour spaces and alpha channels are out of scope for this product intent. Send a JSON body with required fields color and direction. Use the prepaid API when a theme pipeline, sprite sheet generator, accessibility tooling suite, or multiplayer asset service needs a stable contract under KIT balance at $0.002 per successful item; validation failures never consume balance after the engine rejects the request. Pair this endpoint with RGB to HSL or hex to HSL converters when the next step is perceptual adjustment, or with colour contrast checks when the packed integer feeds a WCAG workflow after unpacking.
Integration use cases
CI fixtures and SDK demos
Pin deterministic pack and unpack results in tests so theme pipelines and widget demos never drift on floating colour math.
Technical questions
How do I convert RGB or hex to a decimal integer?
Send JSON with color set to a hex code (for example #FF8000) or an R,G,B triple, and direction set to to_int. The response includes decimal, integer, and rgb_int with the packed 24-bit value.
How do I convert a decimal integer back to RGB?
Send color as the integer (0–16777215) and direction from_int. The response returns r, g, b, hex, and css_rgb.