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

Endianness flag for toArray #183

Closed
s1na opened this issue May 10, 2019 · 2 comments
Closed

Endianness flag for toArray #183

s1na opened this issue May 10, 2019 · 2 comments

Comments

@s1na
Copy link

s1na commented May 10, 2019

Hello,

We rely heavily on big numbers and are discussing switching to a library that polyfills to native BigInts, and that's how I found your great library.

Internally we mostly use big endian representation and If I'm not mistaken the toArray (and fromArray) methods work with little endian representation. I was wondering if you'd consider adding a flag for this to the relevant methods (or would accept a PR doing this).

Thanks

@peterolson
Copy link
Owner

peterolson commented May 10, 2019

Wouldn't it be pretty simple to just call .reverse() on the arrays? IMHO that would be a more readable way to change the order than passing in an extra boolean argument to the toArray/fromArray functions.

Also, toArray and fromArray are already big-endian, i.e. the most significant digit is the first element in the array.

bigInt(4).toArray(2)
/// {"value":[1,0,0],"isNegative":false}
bigInt.fromArray([1, 0, 0], 2).toString()
/// "4"

@s1na
Copy link
Author

s1na commented May 10, 2019

Sorry, I mistakenly got that impression from #39 (Note that the array representation is small endian).

@s1na s1na closed this as completed May 10, 2019
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

2 participants