十六进制代码如何转换为RGB 255值?

时间:2023-01-17 20:15:39

I know that 0 through F represent 0-15, and hex codes are split into 3 groups of two digit hexadecimals, but how is the value 0 through 255 reached with these two digits for R, G, and B? For example #FF FF FF is #1515 1515 1515, it's displayed as white and equal to R=255, G=255, B=255, but how do two 15's equal 255? Multiplied they're only 225.

我知道0到F表示0-15,而十六进制码被分成3组两位数的十六进制,但是0到255的值是如何达到这两个数字的R, G和B的?例如,FF是#1515 1515 1515,它显示为白色,等于R=255, G=255, B=255,但是两个15怎么等于255呢?增加他们只有225。

3 个解决方案

#1


1  

Its the number base.

其数量基础。

(FF)_16 = 15*16^1 + 15*16^0 = (255)_10

(FF)_16 = 15 16 * 16 ^ 1 + 15 * ^ 0 =(255)_10

FF are in base 16 while your 255 are in base 10. so you will need to apply base conversion to get the number in the other base.

FF是16,而你的255是在10的基础上。所以你需要应用碱基转换来得到另一个碱基的数字。

you may wanna read up more about it from this link

你可能想从这个链接了解更多。

#2


2  

For # 15 15 you don't do 15*15. As the number is hex (base 16) not decimal (base 10) you'll do 161*15 + 160*15 which will evnetually come out to be 255.

15 15,你不会做15*15。因为这个数字是十六进制(base 16)而不是十进制(基数10),你会做161*15 + 160*15,最终结果是255。

Decimal 255 in different bases is represented as

在不同的碱基中表示为。

  • Binary (base 2) 11111111 = 27*1 + 26*1 + 25*1 + ...
  • 二进制(基数2)11111111 = 27*1 + 26*1 + 25*1 +…
  • Octal (base 8) 377 = 82*3 + 81*7 + 80*7
  • 八进制(基数8)377 = 82*3 + 81*7 + 80*7。

#3


0  

It looks like you misunderstand what is meant by 0x0~0xF representing 0~15. 0xF does not represent the number 15; it represents a single digit with a value of 15. So 0x10 is not the number 1 concatenated with a 0 to produce 10 (this wouldn't make sense anyway, as 0xA is 10); rather, you might want to think of it as having been counted up to from 0x0.

看起来您误解了0x0~0xF表示0~15的含义。0xF不代表数字15;它表示一个值为15的个位数。因此,0x10不是第1个连接到0的数字,产生10(这是没有意义的,因为0xA是10);相反,您可能想把它看作是从0x0开始计算的。

0x0 (0), 0x1 (1), 0x2 (2), 0x3 (3), 0x4 (4), 0x5 (5), 0x6 (6), 0x7 (7), 0x8 (8), 0x9 (9), 0xA (10), 0xB (11), 0xC (12), 0xD (13), 0xE (14), 0xF (15), 0x10 (16).

0 x0(0),0 x1(1),0 x2(2),0 x3(3),0 x4(4),0 x5(5),0 x6(6),0 x7(7),0×8(8),0 x9(9),0 xa(10),0 xb(11),0 xc(12),0 xd(13),0 xe(14),0 xf(15),0 x10(16)。

#1


1  

Its the number base.

其数量基础。

(FF)_16 = 15*16^1 + 15*16^0 = (255)_10

(FF)_16 = 15 16 * 16 ^ 1 + 15 * ^ 0 =(255)_10

FF are in base 16 while your 255 are in base 10. so you will need to apply base conversion to get the number in the other base.

FF是16,而你的255是在10的基础上。所以你需要应用碱基转换来得到另一个碱基的数字。

you may wanna read up more about it from this link

你可能想从这个链接了解更多。

#2


2  

For # 15 15 you don't do 15*15. As the number is hex (base 16) not decimal (base 10) you'll do 161*15 + 160*15 which will evnetually come out to be 255.

15 15,你不会做15*15。因为这个数字是十六进制(base 16)而不是十进制(基数10),你会做161*15 + 160*15,最终结果是255。

Decimal 255 in different bases is represented as

在不同的碱基中表示为。

  • Binary (base 2) 11111111 = 27*1 + 26*1 + 25*1 + ...
  • 二进制(基数2)11111111 = 27*1 + 26*1 + 25*1 +…
  • Octal (base 8) 377 = 82*3 + 81*7 + 80*7
  • 八进制(基数8)377 = 82*3 + 81*7 + 80*7。

#3


0  

It looks like you misunderstand what is meant by 0x0~0xF representing 0~15. 0xF does not represent the number 15; it represents a single digit with a value of 15. So 0x10 is not the number 1 concatenated with a 0 to produce 10 (this wouldn't make sense anyway, as 0xA is 10); rather, you might want to think of it as having been counted up to from 0x0.

看起来您误解了0x0~0xF表示0~15的含义。0xF不代表数字15;它表示一个值为15的个位数。因此,0x10不是第1个连接到0的数字,产生10(这是没有意义的,因为0xA是10);相反,您可能想把它看作是从0x0开始计算的。

0x0 (0), 0x1 (1), 0x2 (2), 0x3 (3), 0x4 (4), 0x5 (5), 0x6 (6), 0x7 (7), 0x8 (8), 0x9 (9), 0xA (10), 0xB (11), 0xC (12), 0xD (13), 0xE (14), 0xF (15), 0x10 (16).

0 x0(0),0 x1(1),0 x2(2),0 x3(3),0 x4(4),0 x5(5),0 x6(6),0 x7(7),0×8(8),0 x9(9),0 xa(10),0 xb(11),0 xc(12),0 xd(13),0 xe(14),0 xf(15),0 x10(16)。