const decimalNumber = 255; const hexNumber = decimalNumber.toString(16); console.log(hexNumber);
In this above code, the decimal 255 is converted to its hexadecimal equivalent using the toString() method with a radix of 16. The resulting hexadecimal number ff is then logged to the console.
The resulting hexadecimal number is in lowercase, but you can easily convert it to uppercase using the toUpperCase() method of the String object, like this:
const decimalNumber = 255; const hexNumber = decimalNumber.toString(16); console.log(hexNumber.toUpperCase());
You can see that it will output the hexadecimal number in uppercase format.
Niva Shah is a Software Engineer with over eight years of experience. She has developed a strong foundation in computer science principles and a passion for problem-solving.