js hex to decimal code example
Example 1: javascript convert string to 2 decimal
var twoPlacedFloat = parseFloat(yourString).toFixed(2)
Example 2: javascript convert number to hex
yourNumber = parseInt(hexString, 16);
Example 3: to hex javascript
var rgbToHex = function (rgb) {
var hex = Number(rgb).toString(16);
if (hex.length < 2) {
hex = "0" + hex;
}
return hex;
};
Example 4: convert hexadecimal to decimal js
yourNumber = parseInt(hexString, 16);
Example 5: DECIMAL TO BINARY CONVERSION javascript
function convertToBinary(x) {
let bin = 0;
let rem, i = 1, step = 1;
while (x != 0) {
rem = x % 2;
console.log(
`Step ${step++}: ${x}/2, Remainder = ${rem}, Quotient = ${parseInt(x/2)}`
);
x = parseInt(x / 2);
bin = bin + rem * i;
i = i * 10;
}
console.log(`Binary: ${bin}`);
}
let number = prompt('Enter a decimal number: ');
convertToBinary(number);
Example 6: hex string to int javascript
console.log(hex.toString(16));