Conversion method for RGB color and 16 binary colors

Source: Internet
Author: User

Common ways to represent colors in Web pages are:

1.Color name (color name) with color name to specify the color, this method is concise and intuitive, one can see what color, but the biggest disadvantage is that the name of the color is too few, can not effectively represent some of the more rich color

2.RGB (RGB notation)

3.HEX (hexadecimal notation)

RGB notation and hexadecimal notation can be very good to show some of the more rich colors, but we use 16 of the more, the syntax for #rrggbb, the following is the conversion method I just developed:

We all know that.

RGB notation RGB (255,255,255) = hexadecimal notation #ffffff, both of which represent white

RGB notation RGB (0,0,0) = hexadecimal notation #000000, both of which represent black

So RGB notation RGB (100,150,245) = hexadecimal notation #??????

RGB is the value of 0~255,hex is the value of 0123456789ABCDEF these 16 characters, see below Rgb-hex table


RGB HEX

0 00

1 01

2 02

3 03

4 04

5 05

6 06

7 07

8 08

9 09

Ten 0A

0B

0C

0D

0E

0F

10

11

12

13

14

15

16

17

18

19

1A

1B

1C

1D

1E

1F

20

21

22

23

24

Panax 25

26

27

28

29

2A

2B

2C

2D

2E

2F

30

31

32

Wuyi 33

34

35

36

37

38

39

3A

3B

3C

3D

3E

3F

40

41

42

43

44

45

46

47

48

49

4 A

4 B

4C

4D

4E

4F

50

Bayi 51

52

53

54

55

56

57

58

59

5A

5B

5C

5D

94 5E

5F

60

61

98 62

© 63

64

101 65

102 66

103 67

104 68

69

106 6A

107 6B

108 6C

109 6D

6E

111 6F

70

113 71

72

73

74

117 75

118 76

119 77

78

121 79

122 7A

123 7B

124 7C

7D

126 7E

127 7F

80

129 81

82

131 83

84

133 85

134 86

135 87

136 88

137 89

138 8A

139 8B

8C

141 8D

142 8E

143 8F

144 90

145 91

146 92

147 93

148 94

149 95

96

151 97

98

153 99

154 9A

155 9B

156 9C

157 9D

158 9E

159 9F

A0

161 A1

162 A2

163 A3

164 A4

165 A5

166 A6

167 A7

168 A8

169 A9

$ AA

171 AB

172 AC

173 AD

174 AE

175 AF

176 B0

177 B1

178 B2

179 B3

B4

181 B5

182 B6

183 B7

184 B8

185 B9

186 BA

187 BB

188 BC

189 BD

the BE

191 BF

192 C0

193 C1

194 C2

195 C3

196 C4

197 C5

198 C6

199 C7

C8

201 C9

202 CA

203 CB

204 CC

205 CD

206 CE

207 CF

208 D0

209 D1

D2

211 D3

212 D4

213 D5

214 D6

215 D7

216 D8

217 D9

218 DA

219 DB

DC

221 DD

222 DE

223 DF

224 E0

225 E1

226 E2

227 E3

228 E4

229 E5

E6

231 E7

232 E8

233 E9

234 EA

235 EB

236 EC

237 ED

238 EE

239 EF

F0

241 F1

242 F2

243 F3

244 F4

245 F5

246 F6

247 F7

248 F8

249 F9

+ FA

251 FB

252 FC

253 FD

254 FE

255 FF

Through this table we can find RGB in the 0 corresponding to the hex 00,1 corresponding to 01 ... 9 corresponds to 09

10 corresponds to the 0a,11 corresponding to 0B ... 15 corresponds to 0F

16 corresponds to the 10

Here a total of 17 pairs, minus a pair of special 0 corresponding 00, the remaining 16 pairs

Everyone should find the rule, RGB value is 16 times the first hex and hex of the second digit, the number 101 under the RGB and hex are the same, the difference is the hex is two digits, in front of 0 can be, 10 corresponds to a,11 corresponding to the corresponding c,13 D, 14 corresponds to the e,15 corresponding F, the following example to illustrate the RGB to hex conversion method

Example 1:rgb (11,111,222) =#??????

11÷16=0 11 11 corresponds to B front 0 so hex data is 0 b

111÷16=6 15 15 corresponds to f then hex data is 6F

222÷16=13 remainder 14 13 corresponds to D 14 for E so hex data for de

Together, hex data is #0b6fde.

Example 2:rgb (0,16,255) =#??????

0 Direct Correspondence 00

16÷16=1 remaining 0 hex data is 10

255÷16=15 remainder 15 15 corresponds to f hex data for FF

Together, hex data is #0010ff.

Hex conversion RGB Needless to say, the upside is all right.

This article starting address: http://tianle.name/wlyy/275 reprint please indicate the source


Conversion method for RGB color and 16 binary colors

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.