Commit c960636d by Oliver Woodman

Stylistic cleanup.

parent cf27b83e
......@@ -127,19 +127,19 @@ public final class ParsableBitArray {
/**
* Reads up to 32 bits.
*
* @param n The number of bits to read.
* @param numBits The number of bits to read.
* @return An integer whose bottom n bits hold the read data.
*/
public int readBits(int n) {
if (n == 0) {
public int readBits(int numBits) {
if (numBits == 0) {
return 0;
}
int returnValue = 0;
// While n >= 8, read whole bytes.
int numBytes = (n / 8);
for (int i = 0; i < numBytes; i ++) {
// Read as many whole bytes as we can.
int wholeBytes = (numBits / 8);
for (int i = 0; i < wholeBytes; i++) {
int byteValue;
if (bitOffset != 0) {
byteValue = ((data[byteOffset] & 0xFF) << bitOffset)
......@@ -147,14 +147,15 @@ public final class ParsableBitArray {
} else {
byteValue = data[byteOffset];
}
n -= 8;
returnValue |= (byteValue & 0xFF) << n;
numBits -= 8;
returnValue |= (byteValue & 0xFF) << numBits;
byteOffset++;
}
if (n > 0) {
int nextBit = bitOffset + n;
byte writeMask = (byte) (0xFF >> (8 - n));
// Read any remaining bits.
if (numBits > 0) {
int nextBit = bitOffset + numBits;
byte writeMask = (byte) (0xFF >> (8 - numBits));
if (nextBit > 8) {
// Combine bits from current byte and next byte.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment