I have written a function in javascript to convert an integer form of colour from db to hex colour format.But I am unable to convert hex colour string to int form. Also parseInt(color.substr(1), 16)
is giving different result.
<html>
<body>
<button onclick="myFunction()">Try it</button>
<p id="test"></p>
<script>
function myFunction() {
var color="#ff0000";
var num = -65536;
var alphalessHexString =getHexColor(num);
var n = alphalessHexString+"</br>";
var ques="i want a function to convert "+color +" to "+num;
document.getElementById("test").innerHTML = n+ques;
}
function getHexColor(number){
return "#"+((number)>>>0).toString(16).slice(-6);
}
</script>
</body>
</html>
parseInt(color.substr(1), 16)
var color="#ff0000"; console.log(parseInt(color.substr(1), 16))
-> outputs16711680
... why is that not expected?