DustinRiley
DustinRiley

Reputation: 565

Hexadecimal in Android

I've been working with Hex Color codes in android lately. I have an application that uses a shared preference to save the hex value. I was looking in the shared preference save file and I noticed that instead of saving it as 0xFFFFFFFF, it saves it as -263173. Why does it do it this way. It's not causing any problems, and it pulls it and uses it just fine, but it's somewhat confusing to me when I'm trying to alter values in the file myself, and I want to understand why it's doing it this way. Thank you.

Upvotes: 2

Views: 238

Answers (1)

Pascal Piché
Pascal Piché

Reputation: 610

The color is stored like a simple signed Int, the first bit is 1 and make a negative value if you edit them directly. You should read it like a bits to get the right value.

Upvotes: 1

Related Questions