Module: GPS_PVT::Util::BitOp
- Defined in:
- lib/gps_pvt/util.rb
Constant Summary collapse
- MASK =
(1..8).collect{|i| (1 << i) - 1}.reverse
Class Method Summary collapse
Class Method Details
.extract(src_bytes, bits_list, offset = 0) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/gps_pvt/util.rb', line 128 def BitOp.extract(src_bytes, bits_list, offset = 0) res = [] bits_list.inject(offset.divmod(8) + [offset]){|(qM, rM, skip), bits| qL, rL = (skip += bits).divmod(8) v = src_bytes[qM] & MASK[rM] res << if rL > 0 then src_bytes[(qM+1)..qL].inject(v){|v2, b| (v2 << 8) | b} >> (8 - rL) else src_bytes[(qM+1)..(qL-1)].inject(v){|v2, b| (v2 << 8) | b} end [qL, rL, skip] } res end |