Why is Java able to store 0xff000000 as an int?

前端 未结 5 1005
说谎
说谎 2020-12-01 19:33

An integer\'s max value in Java is 2147483647, since Java integers are signed, right?

0xff000000 has a numeric value of 4278190080.

Yet I see Java code like

5条回答
  •  情书的邮戳
    2020-12-01 19:54

    Something probably worth pointing out - this code is not meant to be used as an integer with a numerical value; The purpose is as a bitmask to filter the alpha channel out of a 32 bit color value. This variable really shouldn't even be thought of as a number, just as a binary mask with the high 8 bits turned on.

提交回复
热议问题