Posted By

math89 on 08/21/10


Tagged

color RGB hexadecimal


Versions (?)

Convert RGB to Hexadecimal using JavaScript


 / Published in: JavaScript
 

URL: http://www.devcurry.com/2010/08/convert-rgb-to-hexadecimal-using.html

You have a RGB value and want to convert it into Hexadecimal mode, here’s how to do it using JavaScript.

  1. function Rgb() {
  2. var red = returnHex(200);
  3. var green = returnHex(255);
  4. var blue = returnHex(155);
  5. var hex = "#" + red + green + blue;
  6.  
  7. alert(hex);
  8. }
  9.  
  10. // Convert to Hex
  11. function returnHex(num) {
  12. // Hex can store 16 different values in 1 character
  13. if (num == null) return "00";
  14. num = num.length < 2 ? "0" + num : num
  15. return num.toString(16);
  16. }

Report this snippet  

You need to login to post a comment.