AsInt64 returns the int constituted from the rightmost bits in the bit array.
(nbits uint)
| 204 | // AsInt64 returns the int constituted from the rightmost bits in the |
| 205 | // bit array. |
| 206 | func (d BitArray) AsInt64(nbits uint) int64 { |
| 207 | if d.lastBitsUsed == 0 { |
| 208 | // Fast path. |
| 209 | return 0 |
| 210 | } |
| 211 | |
| 212 | lowPart := d.words[len(d.words)-1] >> (numBitsPerWord - d.lastBitsUsed) |
| 213 | highPart := word(0) |
| 214 | if nbits > uint(d.lastBitsUsed) && len(d.words) > 1 { |
| 215 | highPart = d.words[len(d.words)-2] << d.lastBitsUsed |
| 216 | } |
| 217 | combined := lowPart | highPart |
| 218 | signExtended := int64(combined<<(numBitsPerWord-nbits)) >> (numBitsPerWord - nbits) |
| 219 | return signExtended |
| 220 | } |
| 221 | |
| 222 | // LeftShiftAny performs a logical left shift, with a possible |
| 223 | // negative count. |
no outgoing calls
no test coverage detected