Can js operate a hexadecimal number that converts a decimal number into a 2-byte hexadecimal number?

the application scenario is to pass a decimal color value in the background:-65536. You want the final conversion result to be FFFF0000
, but the conversion method of js is wrong. The problem is that-65536 = > FFFF0000 is a 2-byte conversion, but js is not.
for advice ~ Thank you in advance.

Apr.09,2021

function decimalToHexString(number)
{
  if (number < 0)
  {
    number = 0xFFFFFFFF + number + 1;
  }

  return number.toString(16).toUpperCase();
}
decimalToHexString(-65536) //"FFFF0000"
Menu