Is there any package/library that makes bitwise operations as simple
as with an Integer, but for larger numbers (as in a ByteArray).

Something that allows me to "slice" a sequence of bits, or extract
some using the same protocol as with a String of ones and zeros.

Now when I need to work with sequence of bits, I convert an Integer to
a zero padded version of it up a known size, and then do #copyFrom:to:
to extract what I need and read back the number from it.

I could use a bytearray for it, but as its name implies, it is
oriented towards bytes rather than bits (as in the case of Integer).

Now I do stuff like the following to to extract the first 5 bits of a
fixed length 256 bit array (an Integer).

Integer
  readFrom:
    (((SHA256 hashMessage: message)) asInteger
      printStringBase: 2 length: 256 padded: true)
       copyFrom: 1 to: 5)
  base: 2

I understand bitwise operations, but I couldn't find something that
does the above in a conciser way.

Performance in my case isn't critical, but working with strings is
probably two orders of magnitude slower than manipulating bits in
integers or ByteArrays

Regards,

Esteban A. Maringolo

Reply via email to