class Bit

Simple Bit array class to hold state for our tree drawing class.

Public Class Methods

new(bm = 0) click to toggle source

create a bit store using Fixnum. Initialize to 0.

# File lib/chart/bit.rb, line 5
def initialize(bm = 0)
  @bm = bm
end

Public Instance Methods

clear(i) click to toggle source

Set bit i to 0.

# File lib/chart/bit.rb, line 15
def clear(i)
      @bm &= 0 << i
end
clear?(i) click to toggle source

Return true if bit i is clear

# File lib/chart/bit.rb, line 25
def clear?(i)
  @bm[i] == 0
end
set(i) click to toggle source

set the bit i to 1. Relies on auto promotion of Fixnum to Bignum.

# File lib/chart/bit.rb, line 10
def set(i)
      @bm |= 1 << i
end
set?(i) click to toggle source

Return true if bit i is set

# File lib/chart/bit.rb, line 20
def set?(i)
  @bm[i] == 1
end
to_s() click to toggle source

print the Bit array as a binary number.

# File lib/chart/bit.rb, line 30
def to_s
  @bm.to_s(2)
end