Untitled
unknown
javascript
a year ago
859 B
5
Indexable
function hexToDecimal(hexString) { // Remove any leading '0x' if present if (hexString.startsWith('0x')) { hexString = hexString.slice(2); } // Convert the hex string to a decimal number const decimalNumber = parseInt(hexString, 16); // Check if the conversion is successful if (isNaN(decimalNumber)) { return 'Invalid hexadecimal number'; } return decimalNumber; } function decimalToHex(decimalNumber) { // Check if the input is a valid number if (isNaN(decimalNumber)) { return 'Invalid decimal number'; } // Convert the decimal number to a hexadecimal string const hexString = decimalNumber.toString(16).toUpperCase(); return hexString; } var color = "FFFFFF" console.log(color); console.log(hexToDecimal(color)) console.log(hexToDecimal(color) - 10) console.log(decimalToHex(hexToDecimal(color) - 10))
Editor is loading...
Leave a Comment