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

toString, toBuffer only return low bytes for smaller (signed) ints #20

Closed
proehlen opened this issue Sep 12, 2018 · 2 comments
Closed
Labels

Comments

@proehlen
Copy link

proehlen commented Sep 12, 2018

Hi, I really like your library - thanks for sharing it. I'm having the issue described above.

const { Int64 } = require('int64_t');

const myInt = new Int64(-1);
console.log(myInt.toString(16)); // ffffffff
console.log(myInt.toBuffer()); // <Buffer 00 00 00 00 ff ff ff ff>

To make a 64 bit (signed) int out of those return values I would have to test the highest bit in the lowest word and, if set, fill the high word with FF bytes which is the kind of extra processing I was hoping to avoid by using your library.

This is the result I would expect:

const { Int64 } = require('int64_t');

const myInt = new Int64(-1);
console.log(myInt.toString(16)); // ffffffffffffffff
console.log(myInt.toBuffer()); // <Buffer ff ff ff ff ff ff ff ff>
@gucchisk gucchisk added the bug label Oct 6, 2018
gucchisk added a commit that referenced this issue Oct 9, 2018
gucchisk added a commit that referenced this issue Oct 9, 2018
@gucchisk
Copy link
Owner

gucchisk commented Oct 9, 2018

I'm sorry for replaying so late.
And thank you for using and create this issue.

This bug is fixed by #21.

But sorry, myInt.toString(16) is -1.
This is the specifications of this library.
If you want to get ffffffffffffffff, please write as stated below.

const { Int64 } = require('int64_t');
const myInt = new Int64(-1);
console.log(myInt.toUnsigned().toString(16));  // ffffffffffffffff
console.log(myInt.toBuffer());  // <Buffer ff ff ff ff ff ff ff ff>

Best regard.

@gucchisk
Copy link
Owner

Fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants