Commit c960636d by Oliver Woodman

Stylistic cleanup.

parent cf27b83e
...@@ -127,19 +127,19 @@ public final class ParsableBitArray { ...@@ -127,19 +127,19 @@ public final class ParsableBitArray {
/** /**
* Reads up to 32 bits. * 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. * @return An integer whose bottom n bits hold the read data.
*/ */
public int readBits(int n) { public int readBits(int numBits) {
if (n == 0) { if (numBits == 0) {
return 0; return 0;
} }
int returnValue = 0; int returnValue = 0;
// While n >= 8, read whole bytes. // Read as many whole bytes as we can.
int numBytes = (n / 8); int wholeBytes = (numBits / 8);
for (int i = 0; i < numBytes; i ++) { for (int i = 0; i < wholeBytes; i++) {
int byteValue; int byteValue;
if (bitOffset != 0) { if (bitOffset != 0) {
byteValue = ((data[byteOffset] & 0xFF) << bitOffset) byteValue = ((data[byteOffset] & 0xFF) << bitOffset)
...@@ -147,14 +147,15 @@ public final class ParsableBitArray { ...@@ -147,14 +147,15 @@ public final class ParsableBitArray {
} else { } else {
byteValue = data[byteOffset]; byteValue = data[byteOffset];
} }
n -= 8; numBits -= 8;
returnValue |= (byteValue & 0xFF) << n; returnValue |= (byteValue & 0xFF) << numBits;
byteOffset++; byteOffset++;
} }
if (n > 0) { // Read any remaining bits.
int nextBit = bitOffset + n; if (numBits > 0) {
byte writeMask = (byte) (0xFF >> (8 - n)); int nextBit = bitOffset + numBits;
byte writeMask = (byte) (0xFF >> (8 - numBits));
if (nextBit > 8) { if (nextBit > 8) {
// Combine bits from current byte and next byte. // 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