As the terms of front-end development, will inevitably encounter color values, strings, and direct digital conversion, blogger wrote a small tool for this purpose, for online conversion between color values.
Pre-knowledge: parseInt , toString
parseInt (value, decidal) value is transmitted as hexadecimal values decidal
parseInt(110, 2) => 6
parseInt(110, 8) => 72
parseInt(110, 10) => 110
parseInt(110, 16) => 272
toString need to first convert the digital conversion by the conversion to the specific band by toString
parseInt(110, 16).toString(8) => '420'
parseInt(110, 16).toString(16) => '110'
parseInt(110, 10).toString(16) => '6e'
When the number is hexadecimal 10 is written 110..toString (16) => '6e' 110 Note that there are two points behind, when a decimal point would think
RGB to hex
rgb(255,123,20) => #ff7b14
Idea: Create an array list list [0] = '#'
list[1] = parseInt(255, 10).toString(16)
list[2] = parseInt(123, 10).toString(16)
list[3] = parseInt(20, 10).toString(16)
Results: list.join ( ''
)
Hex to RGB
Ideas:
ff7b14
Partitioning the array into a list = [ 'ff', '7b', '14']
list[0] = parseInt(list[0] , 16)
list[1] = parseInt(list[1] , 16)
list[2] = parseInt(list[2] , 16)
Results: list.join ( ',')