Esteban A. Maringolo wrote
Hi Richard,
Certainly a BitStream is beyond what I initially thought.
But it could be of some use to play with it, is it available somewhere with a friendly open source license?
I might give it a try using it for my generator (tests are already passing). Your example is almost complete, but if I understand it you're adding the size of the checksum instead of the checksum itself. Nonetheless I think its readability is superior, and I guess that it is better perfomance and memorywise.
Also it could be useful for Base58Encoder I'm expermenting with. Encoding is "simple" but requires the use of a really large integer, I'm stuck at the decoding part now. After that there is a Base32 encoder (to implement a Bech32 encoder as well).
So I might use it in my road of experimentation with these matters. Unless I diverge from this and abandon it as it normally happens. :/
BaseX encode/decode can be simple enough to fit in a small workspace: base := 58. base58Lookup := '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'. myNumber := 12345678901234567890. decode := [ :string | |decodedNumber| decodedNumber := 0. string do: [ :char | decodedNumber := decodedNumber * base +(base58Lookup indexOf: char) - 1 ]. decodedNumber ]. encode := [ :number | |encodedString numDigits toEncode| numDigits := (number numberOfDigitsInBase: base). toEncode := number. encodedString := String new: numDigits. 0 to: numDigits - 1 do: [ :i | |lutIndex| encodedString at: numDigits - i put: (base58Lookup at: toEncode \\ base + 1). toEncode := toEncode // base. ]. encodedString ]. myString := encode value: myNumber. (decode value: myString) = myNumber. The appeal of Base64 is it transforms the // and \\ operations into simple shifts / masks. Cheers, Henry -- Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html