Bytes returns the byte representation of the bits within the bitarray.
()
| 341 | |
| 342 | // Bytes returns the byte representation of the bits within the bitarray. |
| 343 | func (bA *BitArray) Bytes() []byte { |
| 344 | bA.mtx.Lock() |
| 345 | defer bA.mtx.Unlock() |
| 346 | |
| 347 | numBytes := (bA.Bits + 7) / 8 |
| 348 | bytes := make([]byte, numBytes) |
| 349 | for i := 0; i < len(bA.Elems); i++ { |
| 350 | elemBytes := [8]byte{} |
| 351 | binary.LittleEndian.PutUint64(elemBytes[:], bA.Elems[i]) |
| 352 | copy(bytes[i*8:], elemBytes[:]) |
| 353 | } |
| 354 | return bytes |
| 355 | } |
| 356 | |
| 357 | // Update sets the bA's bits to be that of the other bit array. |
| 358 | // The copying begins from the begin of both bit arrays. |