How to convert decimal to hexadecimal in JavaScript

后端 未结 27 2664
臣服心动
臣服心动 2020-11-21 23:05

How do you convert decimal values to their hexadecimal equivalent in JavaScript?

27条回答
  •  青春惊慌失措
    2020-11-21 23:53

    If you are looking for converting Large integers i.e. Numbers greater than Number.MAX_SAFE_INTEGER -- 9007199254740991, then you can use the following code

    const hugeNumber = "9007199254740991873839" // Make sure its in String
    const hexOfHugeNumber = BigInt(hugeNumber).toString(16);
    console.log(hexOfHugeNumber)

提交回复
热议问题