Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BigInt.toString() truncates value with power-of-two radices #51122

Closed
ingria opened this issue Dec 11, 2023 · 0 comments
Closed

BigInt.toString() truncates value with power-of-two radices #51122

ingria opened this issue Dec 11, 2023 · 0 comments

Comments

@ingria
Copy link

ingria commented Dec 11, 2023

Version

v20.5.1

Platform

Linux dev 5.15.0-89-generic # 99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

No response

What steps will reproduce the bug?

const i = 0x6aaf20fed58ba5e6db692909e78e5c5c6525e28d1cfa8bd22dc216729b4841b3;
const big = BigInt(i);

console.log('0x' + big.toString(16))

How often does it reproduce? Is there a required condition?

Radix value should be a power of 2 (2, 4, 8, 16, etc).

What is the expected behavior? Why is that the expected behavior?

The result is the same as the initial value (i):

"0x6aaf20fed58ba5e6db692909e78e5c5c6525e28d1cfa8bd22dc216729b4841b3"

What do you see instead?

Trailing digits are replaced with zeros:

"0x6aaf20fed58ba400000000000000000000000000000000000000000000000000"
@ingria ingria closed this as completed Dec 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant