From af480bdfc3fe1fc2e1217719c93b42b4a0b2c6f0 Mon Sep 17 00:00:00 2001 From: Collin Smith Date: Mon, 3 Aug 2020 16:12:52 -0700 Subject: [PATCH] Created readRaw(int) and added support for correctly reading signed 64 bits --- core/src/com/riiablo/codec/util/BitStream.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/core/src/com/riiablo/codec/util/BitStream.java b/core/src/com/riiablo/codec/util/BitStream.java index 52a1eb3a..3097f611 100644 --- a/core/src/com/riiablo/codec/util/BitStream.java +++ b/core/src/com/riiablo/codec/util/BitStream.java @@ -115,6 +115,10 @@ public class BitStream { return readBoolean() ? 1 : 0; } + public long readRaw(int bits) { + return readUnsigned(bits); + } + public long readUnsigned(int bits) { Validate.inclusiveBetween(0, Long.SIZE, bits, "bits must be in range [0,64]"); if (bits == 0) return 0; @@ -161,6 +165,10 @@ public class BitStream { } public long readSigned(int bits) { + if (bits == Long.SIZE) { + return readRaw(bits); + } + final int shift = Long.SIZE - bits; return readUnsigned(bits) << shift >> shift; }