Substr returns a substring, consisting of the bits from indexes start to end.
(start int, end int)
| 54 | |
| 55 | // Substr returns a substring, consisting of the bits from indexes start to end. |
| 56 | func (b *Bitset) Substr(start int, end int) *Bitset { |
| 57 | if start > end || end > b.numBits { |
| 58 | log.Panicf("Out of range start=%d end=%d numBits=%d", start, end, b.numBits) |
| 59 | } |
| 60 | |
| 61 | result := New() |
| 62 | result.ensureCapacity(end - start) |
| 63 | |
| 64 | for i := start; i < end; i++ { |
| 65 | if b.At(i) { |
| 66 | result.bits[result.numBits/8] |= 0x80 >> uint(result.numBits%8) |
| 67 | } |
| 68 | result.numBits++ |
| 69 | } |
| 70 | |
| 71 | return result |
| 72 | } |
| 73 | |
| 74 | // NewFromBase2String constructs and returns a Bitset from a string. The string |
| 75 | // consists of '1', '0' or ' ' characters, e.g. "1010 0101". The '1' and '0' |