Convert a RGB colour value to Decimal

前端 未结 6 1311
梦谈多话
梦谈多话 2021-02-04 13:09

How do I convert a RGB colour value to just plain decimal?

So I have: RGB(255,255,255) is white
Its decimal equivalent is: 16777215

I have tried thinking it

6条回答
  •  日久生厌
    2021-02-04 13:14

    You need to left-shift the R by 16, the G left by 8 and or both in to the B. Look at the values as bits and all will become clear:

    R 255 = 11111111B G 255 = 11111111B B 255 = 11111111B

    Shift R 16: 111111110000000000000000 Shift G 8: 000000001111111100000000

    or into B: 111111111111111111111111

    Convert to decimal: 16777215

提交回复
热议问题