Convert 8-bit integer to Hex color value in JavaScript
Topics related to client-side programming language.
Post questions and answers about JavaScript, Ajax, or jQuery codes and scripts.
-
Marius
- Posts:107
Convert 8-bit integer to Hex color value in JavaScript
I'm trying to convert 8-bit integer to Hex color value. (e.g. FFFFFF)
The 8-bit color integer is generated with the following formula:
Code: Select all
color = ( [red] * 65536) + ( [green] * 256) + ( [blue] * 1)
In C, it is done by:
Code: Select all
sprintf(colorbuf, "#%6.6x", color);
How can I convert this 8-bit integer value to Hex color value in Javascript?
MarPlo
Posts:186
If you have an integer you can do with:
And it will turn it in to a hex string.
Code: Select all
// White
color = (255 * 65536) + (255 * 256) + (255 * 1); // 16777215
color.toString(16); // 'ffffff'
Similar Topics
- Hour and Minutes togheter in Javascript
JavaScript - jQuery - Ajax
First post
Dear Coursesweb I can not find out how to add the hours + minutes togheter.
<SCRIPT LANGUAGE= JavaScript >
day = new Date()
hr =...
Last post
See and use the following example:
<script>
var day = new Date();
let hr = day.getHours();
let mn = day.getMinutes();
let se =...
- Display message to every minute in Javascript
JavaScript - jQuery - Ajax
First post
Hello,
On eatch minute from the current hour I wanna have an message
I can not find out how to complete
I hope to get something like this (code...
Last post
If you only want to display a message to every minute, just use the setInterval() function. It calls a function repeatedly, over and over again, at...