AbraCalc

RGB to Integer Converter

Pack RGB color values into a single 24-bit integer (used in many graphics APIs and game engines).

Embed this tool on your site
Cite this tool

APA

AbraCalc. (2026). RGB to Integer Converter [Online calculator]. Retrieved from https://abracalc.com/converter/rgb-to-int/

BibTeX

@misc{abracalc-rgb-to-int, author = {AbraCalc}, title = {RGB to Integer Converter}, year = {2026}, howpublished = {\url{https://abracalc.com/converter/rgb-to-int/}} }

Did this tool answer your question?

How to use this tool

  1. Enter red, green, and blue values (0–255 each).
  2. The tool computes the 24-bit packed integer and its hex string.
  3. Use the decimal integer in APIs that accept packed 0xRRGGBB values.

Pack R, G, B values into a single integer: color = (R << 16) | (G << 8) | B. Common in game engines, OpenGL, and low-level graphics APIs.

Formula

A 24-bit RGB integer is formed by packing the three 8-bit channels into a single number using bit shifts:

integer = (R << 16) | (G << 8) | B

Equivalently: integer = R × 65536 + G × 256 + B

The hex string representation is 0x followed by the 6-digit zero-padded hex of that integer.

How it works

Each channel (R, G, B) is first clamped to 0–255 and rounded to an integer. The red channel is shifted 16 bits left, green 8 bits left, and blue occupies the lowest 8 bits; a bitwise OR combines them into one 24-bit value. The decimal result and a 0x-prefixed hex string are both returned.

Common mistake: assuming the packed integer uses an alpha channel — this calculator produces a 24-bit RGB integer (no alpha). Many graphics APIs also support 32-bit ARGB or RGBA integers where an alpha byte occupies either the top or the bottom 8 bits; using the wrong format causes colors to appear transparent or shifted in those APIs.

Worked example

Pack pure red (255, 0, 0) into an integer

  1. Clamp and validate: R = 255, G = 0, B = 0 — all within 0–255.
  2. Shift red: 255 << 16 = 16,711,680 (0xFF0000).
  3. OR with green and blue (both 0): 16,711,680 | 0 | 0 = 16,711,680.
  4. Hex string: 0x + '0' × padding + 'ff0000' = 0xff0000.

Integer (decimal): 16711680 | Hex string: 0xff0000

Common mistakes to avoid

  • Assuming a consistent byte order across all APIs -- some engines use BGR order (B + G x 256 + R x 65536) or include an alpha byte, producing a different integer for the same color.
  • Entering values outside 0 to 255 for any channel -- values above 255 cause bit overflow and produce an integer that decodes to the wrong color.
  • Treating the resulting integer as signed -- in many APIs the integer is an unsigned 32-bit value; interpreting it as signed int32 can give a negative number for colors with R >= 128.

Key terms

24-bit color integer
A single integer that encodes red, green, and blue each as one byte. The format is 0xRRGGBB, occupying bits 16–23 (red), 8–15 (green), and 0–7 (blue).
Bit shift (<<)
Moving the binary digits of a number left by a given number of positions, effectively multiplying by a power of 2. Shifting red left by 16 positions places it in the most significant byte of the 24-bit color integer.
Bitwise OR (|)
An operation that combines two integers by setting each output bit to 1 if either input has a 1 in that position. Used here to merge the three independently shifted channel values into one integer without overlap.
RGB channel
One of the three components of an RGB color — Red, Green, or Blue — each stored as an 8-bit value between 0 and 255 representing intensity.

Frequently asked questions

How is an RGB color packed into an integer?
Red occupies bits 16–23, green bits 8–15, and blue bits 0–7. The formula is: (R << 16) | (G << 8) | B.
What range can the integer be?
0 (black) to 16,777,215 (white, 0xFFFFFF) for 24-bit RGB.

References & sources