// unsigned values only sclass VariableSizeUIntForBitHead is BitIO { // How many bits are written at once settable int chunkSize = 3; settable int value; gettable int bitCount; public void readWrite(BitHead head) { if (head.writeMode()) { bitCount = max(1, numberOfBits(value)); int value = this.value; head.writePartialByte(value, chunkSize); value >>>= chunkSize; while (value != 0) { head.writeBit(1); head.writePartialByte(value, chunkSize); value >>>= chunkSize; } head.writeBit(0); } if (head.readMode()) { int value = head.readPartialByte(chunkSize); int shift = 0; while (!head.isEOF() && head.readBit()) value |= head.readPartialByte(chunkSize) << (shift += 3); ret value; } } }