Format prints out the bit array to the buffer.
(buf *bytes.Buffer)
| 271 | |
| 272 | // Format prints out the bit array to the buffer. |
| 273 | func (d BitArray) Format(buf *bytes.Buffer) { |
| 274 | bitLen := d.BitLen() |
| 275 | buf.Grow(int(bitLen)) |
| 276 | for i := uint(0); i < bitLen/numBitsPerWord; i++ { |
| 277 | w := d.words[i] |
| 278 | // Change this loop if numBitsPerWord changes. |
| 279 | buf.WriteString(byteReprs[(w>>56)&0xff]) |
| 280 | buf.WriteString(byteReprs[(w>>48)&0xff]) |
| 281 | buf.WriteString(byteReprs[(w>>40)&0xff]) |
| 282 | buf.WriteString(byteReprs[(w>>32)&0xff]) |
| 283 | buf.WriteString(byteReprs[(w>>24)&0xff]) |
| 284 | buf.WriteString(byteReprs[(w>>16)&0xff]) |
| 285 | buf.WriteString(byteReprs[(w>>8)&0xff]) |
| 286 | buf.WriteString(byteReprs[(w>>0)&0xff]) |
| 287 | } |
| 288 | remainingBits := bitLen % numBitsPerWord |
| 289 | if remainingBits > 0 { |
| 290 | lastWord := d.words[bitLen/numBitsPerWord] |
| 291 | minShift := numBitsPerWord - 1 - remainingBits |
| 292 | for i := numBitsPerWord - 1; i > int(minShift); i-- { |
| 293 | bitVal := (lastWord >> uint(i)) & 1 |
| 294 | buf.WriteByte('0' + byte(bitVal)) |
| 295 | } |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | // EncodingPartsForBitLen creates a word backing array and the |
| 300 | // "last bits used" value given the given total number of bits. |