On 2003.01.02, Bernard Miller <forbytext / yahoo.com> wrote:
> This works for simple bit masking operations, but I?m
> shifting bits a lot. I need to know the total number
> of bits I?m dealing with, not just the number of bits
> that can be assumed from the size of the number. I
> also need to know the exact order of bits, not just an
> order relative to the most significant bit which is
> all you really know when dealing with values instead
> of bit patterns. 
> 
> The bitvector interface is probably overkill for what
> I want to do, and I seem to need to know perl to
> understand the documentation, but I?ll look into it
> and post a comparison when I?m finished. 

Why not create your own BitString class?  If you can define
the number of operations ...

class BitString
  def initialize(length)
    # length is the length of the bitstring, in bits
    @length = length
    # @bits contains the string of bits -- initialize to 0.
    @bits = sprintf "%0#{@length}b", 0
  end

  def =(value)
    @bits = sprintf "%0#{@length}b", value
  end

  def >>(times)
    # shift right 'times' times.
    ...add code...
  end

  def <<(times)
    # shift left 'times' times.
    ...add code...
  end

  def +(other)
    # add two bitstrings together
    ...add code...
  end

  ...add code for other bitwise operations you need to support...

  def to_s
    @bits
  end
end

You get the idea ...

-- Dossy

-- 
Dossy Shiobara                       mail: dossy / panoptic.com 
Panoptic Computer Network             web: http://www.panoptic.com/ 
  "He realized the fastest way to change is to laugh at your own
    folly -- then you can let go and quickly move on." (p. 70)