convert Integers to RGB values and back with Python

前端 未结 2 1939
庸人自扰
庸人自扰 2020-12-28 20:39

I have two functions, one to return RGB values from a given Integer, and the other function does the reverse, providing it with RGB values it returns an Integer. I\'m testin

2条回答
  •  既然无缘
    2020-12-28 21:01

    There's nothing wrong with your code. The values are different, because you are giving 2147483647 as input, which, translated to hexadecimal, gives 0x7FFFFFFF as an output. On the other hand, 16777215 is 0xFFFFFF in hexadecimal, so you understand there is nothing wrong with your code actually, apart from the fact that you are giving such a big decimal number as an input.

    You can test this if you type:

    print i1 & 0xFFFFFF, i2 # this will return equal values
    

提交回复
热议问题