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