简体   繁体   English

我将如何使用 js 将十进制数转换为十六进制字符串?

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

Decimal input: 76561198291043943十进制输入: 76561198291043943
Hex output: 110000113b74660十六进制输出: 110000113b74660
Hex expected output: 110000113b74667十六进制预期输出: 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.出于某种原因,当我使用以下代码段并执行它时,不会出现预期的结果,但是当我使用https://www.binaryhexconverter.com/decimal-to-hex-converter将十进制数转换为十六进制时字符串,我得到了预期的输出。

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

76561198291043943 is greater than Number.MAX_SAFE_INTEGER . 76561198291043943大于Number.MAX_SAFE_INTEGER

Use BigInt instead:改用BigInt

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Number()将字符串转换为数字而不丢失小数点? - How can I use Number() to convert a string to number without losing the decimal points? 如何在 javascript 中将非常大的十六进制数转换为十进制数 - How to convert a very large hex number to decimal in javascript 如何在 Node.js 中将输出十六进制转换为十进制? - How to convert output hex to decimal in Node.js? Javascript 如何将十进制数转换为具有特定小数位数的字符串 - Javascript How to convert a decimal number to a string with specific number of decimal places 将以字符串形式表示的十进制数转换为仍以字符串形式表示的十六进制格式 - Convert a decimal number represented as a string to its hex format still representing it as a string 如何将非常大的十进制数转换为字符串? - How to convert a very large decimal number to a string? 是否可以在 JS 中将语言环境字符串转换为带有千位分隔符的十进制数? - Is it possible to convert locale string to decimal number with thousand separators in JS? 如何转换一个数字,我用一个逗号从一个字符串替换点到十进制数字 - How to convert a number where I replaced the dot with a comma from a string back to a decimal number 我有一个数字输入,我想转换成十进制反应 js - I have a number input and I want to convert into decimal react js 如何在JavaScript中将字符串中出现的不确定数量的rgb转换为十六进制? - How to convert an indeterminate number of rgb occurrences in a string to hex in JavaScript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM