@param bitOffset first bit to start writing @param array array to write into. Bytes are written most-significant byte first. This is the opposite of the internal representation, which is exposed by #getBitArray() @param offset position in array to start writing @param numBytes how many byte
(int bitOffset, byte[] array, int offset, int numBytes)
| 275 | * @param numBytes how many bytes to write |
| 276 | */ |
| 277 | public void toBytes(int bitOffset, byte[] array, int offset, int numBytes) { |
| 278 | for (int i = 0; i < numBytes; i++) { |
| 279 | int theByte = 0; |
| 280 | for (int j = 0; j < 8; j++) { |
| 281 | if (get(bitOffset)) { |
| 282 | theByte |= 1 << (7 - j); |
| 283 | } |
| 284 | bitOffset++; |
| 285 | } |
| 286 | array[offset + i] = (byte) theByte; |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | /** |
| 291 | * @return underlying array of ints. The first element holds the first 32 bits, and the least |