HEX to Android color int
Handy for Android developers who store or compare colors as ints in Kotlin and Java.
Loading the tool…
Processing and privacy: The result is calculated inside your browser and your data is not sent to any server.
How to use it
- Enter hex in android order.
- The result appears straight away and updates as you edit.
- Copy the result, or copy a link that keeps the same values to share it.
How it is calculated
Unsigned = A × 2^24 + R × 2^16 + G × 2^8 + B, with A = 255 when omitted. If it is 2^31 or more, subtract 2^32 to get the signed int.
Example
Inputs: HEX in Android order = #FF8000. Result: Signed color int: -32768.
#FF8000
-32768
Limits and caveats
- 8-digit input is read in Android order #AARRGGBB, not CSS order.
- In Kotlin, a literal like 0xFFFF8000 needs .toInt() because it exceeds the Int range.
Questions about this tool
Why is an Android color int negative?
Colors are stored in a signed 32-bit int. Opaque colors start with FF, which sets the top bit, so the value reads as negative.
What is the difference between #AARRGGBB and #RRGGBBAA?
Android puts alpha first while CSS puts it last. The same color is written in two orders.
What is white on Android?
Color.WHITE is -1, which is 0xFFFFFFFF, and Color.BLACK is -16777216.
