Class: Resedit::BitConverter
- Inherits:
-
Object
- Object
- Resedit::BitConverter
- Defined in:
- lib/resedit/convert/bitconv.rb
Class Method Summary collapse
Class Method Details
.bits2Bytes(bits, width) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/resedit/convert/bitconv.rb', line 5 def self.bits2Bytes(bits, width) i=0 res=[] while i<bits.length buf=0 cw=0 bsz=0 while cw<width if bsz==0 buf = bits[i] i+=1 bsz=8 end bsz-=1 cw+=1 res << ((buf>>bsz) & 1) end end return res end |
.bytes2Bits(bytes, rwidth, bwidth) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/resedit/convert/bitconv.rb', line 26 def self.bytes2Bits(bytes, rwidth, bwidth) res=[] for i in 0..(bytes.length/rwidth)-1 row=bytes[i*rwidth..i*rwidth+rwidth-1] while row.length < bwidth*8 row << 0 end b=0 for j in 0..row.length-1 b <<= 1 b |= row[j] if (j+1)%8==0 res << (b & 0xFF) b=0 end end end return res end |