SkrtOnDiscord
SkrtOnDiscord

Reputation: 77

How would I use js to convert a decimal to number to a hex string?

Decimal input: 76561198291043943
Hex output: 110000113b74660
Hex expected output: 110000113b74667

For some reason, when I use the following snippet and execute it, the expected result does not occur, but when I use https://www.binaryhexconverter.com/decimal-to-hex-converter to convert a decimal number to a hex string, I get the expected output.

console.log(Number(76561198291043943).toString(16))

Upvotes: 1

Views: 111

Answers (1)

Spectric
Spectric

Reputation: 31992

76561198291043943 is greater than Number.MAX_SAFE_INTEGER.

Use BigInt instead:

console.log(BigInt("76561198291043943").toString(16))

Upvotes: 1

Related Questions