Good day, tell me how to do the color conversion from 0Xffb200 to% RGB.
- the answer to en.so https://stackoverflow.com/questions/5623838/rgb-to-hex-and-hex-to-rgb - slippyk
- Everywhere they give advice on how to convert to hexadecimal. - Artyom Sapsay
|
2 answers
const hex_color = 0Xffb200; let r = hex_color >> 16; let g = (hex_color & 0Xff00) >> 8; let b = hex_color & 0Xff; //rgb 0-255 console.log(r, g, b); // Проценты: console.log(r*100/256, g*100/256, b*100/256); - divide by
0Xffff? not on0X10000? In JS, there is no operator>>? - Andrei NOP - I ask why on 0xFFFF, and not on 0x10000? You get fractional values where they should not be. - Andrei NOP
- 0xFF is not 100%? How then to get 100? - Andrei NOP
- @AndreyNOP 0XFF is not 100%, it is 256 in the 16th system. Get 100 can, if you find a suitable job and pass the interview. - Darth
|
Translated HEX to RGB.
hexDec("#ffb200"); function hexDec(h){ var m=h.slice(1).match(/.{2}/g); m[0]=parseInt(m[0], 16); m[1]=parseInt(m[1], 16); m[2]=parseInt(m[2], 16); console.log(m.join('.')); console.log('R:'+m[0]*100/256+' G:'+m[1]*100/256+' B:'+m[2]*100/256); }; |