Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Color.parseColor returns negative

Tags:

android

I have just tried to do like

System.out.println("color == " + Color.parseColor("#F5F5F5"));

then it returns like

color == -657931

anyone knows why, please?

like image 569
user3898252 Avatar asked Aug 01 '14 06:08

user3898252


1 Answers

First of all parseColor method will return an integer representation of the hexadecimal F5F5F5 which is actually FFF5F5F5 + the opacity of the color.

the decimal value of FFF5F5F5 is 4294309365 which is then converted to integer that will overflow thus giving your that negative number.

here is an example of that overflow

    int i = (int)4294309365L; //4294309365L the decimal representation of FFF5F5F5
    System.out.println(i); //result: -657931
like image 105
Rod_Algonquin Avatar answered Sep 24 '22 11:09

Rod_Algonquin