PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, August 8, 2022

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

 August 08, 2022     decimal, hex, javascript     No comments   

Issue

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))


Solution

76561198291043943 is greater than Number.MAX_SAFE_INTEGER.

Use BigInt instead:

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



Answered By - Spectric
Answer Checked By - Mildred Charles (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing