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

toBinaryString returns 0s #13

Closed
TWiStErRob opened this issue May 13, 2018 · 4 comments
Closed

toBinaryString returns 0s #13

TWiStErRob opened this issue May 13, 2018 · 4 comments

Comments

@TWiStErRob
Copy link

Code: println((-71777214294589696L).toBinaryString())
Output: 0000000000000000000000000000000000000000000000000000000000000000

@TWiStErRob
Copy link
Author

Tried .toUnsignedString(2), toHexString() as well, it's less 0s.

.toUlong().toString() gives a good decimal representation, but I need binary; UTypes don't have toString(radix) methods.

.toUlong().toBigInt().toString(2) gives the right value, but pretty tedious.

.toUBigInt().toString(2) is based on toUnsignedString(10), luckily that's not using toUnsignedString0, so it works.

The bug is in the konversion of formatUnsignedLong from the JDK: when you introduced _this, you forgot to replace the implicit this.toInt() and mask inside digits[], it should be _this.toInt() and mask.

@elect86
Copy link
Collaborator

elect86 commented May 14, 2018

Hi Róbert,

thanks for opening the issue and suggesting the fix, I quickly applied it and it worked.

I'll review all the other call and problems you mentioned with calm.

Btw, push request are welcome for the next time if you want to do it directly.

Shall I publish a release for this fix?

@TWiStErRob
Copy link
Author

The other issues are not really issues, I was just looking to work around this bug.
I guess the only thing you need to look at is "UTypes don't have toString(radix) methods."

No need to push any quick, I decided to just go with fun Int.toBinaryHashString() = java.lang.Integer.toBinaryString(this) instead of pulling your whole lib in, I'm on desktop and targeting latest Java so have the API I need.

@elect86
Copy link
Collaborator

elect86 commented Oct 4, 2018

Added toString(radix) in 1.3 branch

A little late but better than never :p

@elect86 elect86 closed this as completed Oct 4, 2018
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