ForHosting KIT · Images

RGB to RGB565 packer

Turn an RGB color into the 16-bit word a TFT display expects: orange 255, 128, 0 packs to 64512, or 0xFC00. Red keeps five bits, green six and blue five, cut rather than rounded. Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon
If you enter
Resistance (Ω)
255
G
128
B
0
You get
Rgb565
64,512
Hex
0xFC00
Hex digits
FC00
Bits
1111110000000000

Embedded TFT controllers, microcontroller graphics libraries, and many handheld game consoles store each pixel as one sixteen-bit RGB565 word instead of three separate eight-bit channels. This RGB to RGB565 packer takes red, green, and blue integers from zero through two hundred fifty-five and packs them by truncating unused low bits: five bits of red, six bits of green, and five bits of blue, then assembling the classic sixteen-bit layout used by ILI9341, ST7735, ST7789, SSD1351, Adafruit GFX, and TFT_eSPI. The conversion is fully deterministic, performs no rounding, calls no network, and never depends on the clock.

How an RGB color is packed into RGB565

In eight-bit sRGB each of red, green, and blue is an integer from zero through two hundred fifty-five, which is more precision than a sixteen-bit framebuffer can keep. RGB565 spends five bits on red, six bits on green, and five bits on blue because the human eye is more sensitive to green, so the extra bit is spent where it reduces banding the most.

This packer uses the industry-standard truncation method, not rounding: red is shifted right three bits, green is shifted right two bits, and blue is shifted right three bits, discarding the unused low bits. The three fields are then assembled as red shifted left eleven bits, bitwise-or green shifted left five bits, bitwise-or blue, producing a unique unsigned integer from zero through sixty-five thousand five hundred thirty-five.

Pure black packs to zero, pure white packs to the maximum, pure red becomes the familiar F800 hex word, pure green becomes 07E0, and pure blue becomes 001F. There is no silent wrap of two hundred fifty-six, no rounding of the discarded bits, and no network or clock in the path, so the same triple always yields the same sixteen-bit word.

Where an RGB to RGB565 packer earns its keep

Students see it in embedded-systems courses that introduce TFT framebuffers, in game-programming labs that target sixteen-bit handhelds, and in interview warm-ups that ask for the bit layout of RGB565. Tooling authors call the same contract from build scripts to seed palette headers, from property tests that compare a new driver against this oracle, and from design-token pipelines that must emit both a CSS hex and a firmware word from one source of truth.

Pair it with an RGB to hex converter when the next consumer is a stylesheet, with an RGB to decimal integer packer when you need a twenty-four-bit word instead, and with other free deterministic colour tools when you are building a small lab for embedded palette hygiene.

TFT firmware palettes

Turn brand RGB triples into RGB565 words for ILI9341, ST7735, ST7789, and Adafruit GFX colour tables.

Sprite and framebuffer conversion

Pack offline assets into 16-bit C arrays and SPI high/low bytes that match the controller byte order.

Deterministic driver tests

Pin truncated RGB565 goldens in CI so a new graphics helper never silently switches to rounding.

How do I convert RGB to RGB565?

The response rgb565 field is the packed 16-bit word; hex is the 0x-prefixed four-digit form used in firmware.

Does this packer round or truncate the extra bits?

It truncates. Red and blue drop their low 3 bits (>> 3) and green drops its low 2 bits (>> 2). That matches Adafruit GFX, TFT_eSPI, and typical TFT controller examples. There is no rounding.

What happens if a channel is outside 0–255?

Channels are never clamped or wrapped, so a 256 from a broken picker cannot become a wrong pixel.

Is the RGB to RGB565 packer free?

The browser tool runs free on your device.

Why does green get six bits and red and blue only five?

The human eye is more sensitive to green, so RGB565 spends the extra bit there. The 5-6-5 split is the sixteen-bit layout used by the common TFT controllers this tool targets.

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.

POSThttps://api.kit.forhosting.com/color/rgb-rgb565

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.

curl -X POST https://api.kit.forhosting.com/color/rgb-rgb565 \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"r":255,"g":128,"b":0}'
{
  "r": 255,
  "g": 128,
  "b": 0
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "color.rgb_rgb565",
  "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.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

min_channel0
max_channel255
HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

Channels outside zero through two hundred fifty-five are rejected with a clear invalid_input error rather than silently wrapped or clamped.

How RGB565 packing works and what the response contains

The response echoes the validated channels r, g, and b, returns the packed integer as rgb565, a 0x-prefixed four-digit uppercase hex string, the four hex digits alone, a sixteen-character binary string, the truncated fields r5, g6, and b5, the reconstructed eight-bit channels r_q, g_q, and b_q obtained by shifting the truncated fields back left, the high and low bytes that an SPI transfer to an ILI9341-class controller expects in that order, CSS rgb strings for the original and quantized colours, a method tag truncate_rgb565, the bit formula, and max always equal to 65535.

How r, g, and b are validated and why truncation stays honest

Outer whitespace on string channels is trimmed; an optional leading plus is allowed only when the remaining characters are decimal digits that parse to an integer in range. Values such as one hundred twenty-eight point five fail validation rather than being rounded, and negative numbers or two-hundred-fifty-six-plus values fail with a message that names the channel and states that it must stay inside zero through two hundred fifty-five. Missing fields and empty strings after trimming are rejected the same way. The preferred fields are r for red, g for green, and b for blue. Aliases red and capital R, green and capital G, and blue and capital B are accepted so spreadsheets, query strings, and typed forms can reuse the contract without renaming columns. A bare JSON number is accepted only when it is a finite integer inside zero through two hundred fifty-five. The reconstructed channels r_q, g_q, and b_q show the colour that actually lands in the framebuffer after those bits are gone, which is the honest preview artists need before they commit a palette.

Where an RGB to RGB565 packer earns its keep

Firmware authors meet this mapping when a brand guide lists eight-bit RGB swatches and the display driver wants a uint16_t colour, when a sprite sheet is converted offline into a 16-bit C array, or when a serial log prints a packed word and the desk needs the matching hex constant. On this page the work runs entirely in your browser; through the API each successful pack costs $0.002, failed validation is not charged, and nothing is stored after the response returns. That split—free interactive exploration and a priced, identical API—matches the rest of the KIT tier-A catalog and lets you move from a bench demo or lecture slide to an automated firmware pipeline without changing the packed result.

Read the full KIT documentation →