--- Begin Message ---
Hi Esteban,

When you say "extract", what exactly do you mean?

Let's suppose you have 86, i.e. 2r1010110 
Which case do you want?

a) 2r1010110 "2 to 5 = 2r10[1011]0 = 2r1011 = 11"

or

b) 2r1010110 "2 to 5 = 2r10[1011]0 = 2r00[1011]0 =  2r0010110 =  22"
Both cases can be dealt with bit shifting and a bitAnd with optimal performance.

----------------- 
Benoît St-Jean 
Yahoo! Messenger: bstjean 
Twitter: @BenLeChialeux 
Pinterest: benoitstjean 
Instagram: Chef_Benito
IRC: lamneth 
Blogue: endormitoire.wordpress.com 
"A standpoint is an intellectual horizon of radius zero".  (A. Einstein) 

    On Sunday, March 4, 2018, 2:31:21 PM EST, Esteban A. Maringolo 
<emaring...@gmail.com> wrote:  
 
 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

  

--- End Message ---

Reply via email to