Class: BitUtil
- Inherits:
-
Object
- Object
- BitUtil
- Defined in:
- lib/visitor/numbering_visitor.rb
Instance Method Summary collapse
- #bitGreaterThanOrEqualTo(startOffset, v1, v2) ⇒ Object
-
#initialize ⇒ BitUtil
constructor
A new instance of BitUtil.
- #leftBit(n) ⇒ Object
- #leftMostBitToRightOf(bitNumber, n) ⇒ Object
- #rightBit(n) ⇒ Object
Constructor Details
#initialize ⇒ BitUtil
Returns a new instance of BitUtil.
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/visitor/numbering_visitor.rb', line 27 def initialize @masks = [ 0xffff, 0xff ] @rightTable = [ 0 ] @leftTable = [ 0 ] (1..255).each do |val| @rightTable << rightOneBit(val) @leftTable << leftOneBit(val) end end |
Instance Method Details
#bitGreaterThanOrEqualTo(startOffset, v1, v2) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/visitor/numbering_visitor.rb', line 48 def bitGreaterThanOrEqualTo(startOffset, v1, v2) map = (1 << (startOffset - 1)) while (startOffset < 64) do if (((v1 & map) != 0) && ((v2 & map) != 0)) then return startOffset else startOffset += 1 map = map << 1 end end end |
#leftBit(n) ⇒ Object
43 44 45 46 |
# File 'lib/visitor/numbering_visitor.rb', line 43 def leftBit(n) shiftCount, n = shiftToByteLeft(n) @leftTable[n & 0xff] + shiftCount end |
#leftMostBitToRightOf(bitNumber, n) ⇒ Object
60 61 62 63 |
# File 'lib/visitor/numbering_visitor.rb', line 60 def leftMostBitToRightOf(bitNumber, n) mask = getMask(bitNumber + 1) return leftBit(n & mask) end |
#rightBit(n) ⇒ Object
38 39 40 41 |
# File 'lib/visitor/numbering_visitor.rb', line 38 def rightBit(n) shiftCount, n = shiftToByteRight(n) @rightTable[n & 0xff] + shiftCount end |