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

Base 36 constructor #48

Open
WORMSS opened this issue Jun 1, 2023 · 3 comments
Open

Base 36 constructor #48

WORMSS opened this issue Jun 1, 2023 · 3 comments

Comments

@WORMSS
Copy link

WORMSS commented Jun 1, 2023

Hello, For input, you have 0b101010101010 and 0xa6e etc etc..

You have the ability to do const b36 = BitSet('10101010110101010101010101010').toString(36)
But not sure how to get it back in const bs = BitSet(b36)

I am sure you are gonna say it's not possible.. but I just wanted to confirm that something like BitSet(b36, 36) didn't exist?

@infusion
Copy link
Collaborator

infusion commented Jun 1, 2023

Well, Bitset.js has two static functions BitSet.fromHexString and BitSet.fromBinaryString. Currently there is no option for an arbitrary base, but I think it would be a nice addition. Maybe something like BitSet.fromString(str, base)`, what do you think?

@WORMSS
Copy link
Author

WORMSS commented Jun 1, 2023

Constructor, static function, I am easy either way.. ❤️

I was just looking through your parse(P, val) to see if it was possible.. I got a little confused by the len = 8 for hexidecimal part, so I was unsure what would be needed for passing in 36 or even arbitrary lengths..

@infusion
Copy link
Collaborator

infusion commented Jun 1, 2023

The len is just max block length, that is cut out at each time. For base 2 it's 32, for 16 it's 8, for a general base b it would be Math.log(2**32) / Math.log(b). However, this only makes sense for 2^k-bases with the current implementation. And I think implementing a static function is much cleaner, instead of coming up with an arbitrary prefix, such as 36:XYZ or something.

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