summaryrefslogtreecommitdiffstats
path: root/src/java/com/jogamp/common/util/Bitstream.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/java/com/jogamp/common/util/Bitstream.java')
-rw-r--r--src/java/com/jogamp/common/util/Bitstream.java42
1 files changed, 32 insertions, 10 deletions
diff --git a/src/java/com/jogamp/common/util/Bitstream.java b/src/java/com/jogamp/common/util/Bitstream.java
index 7bf0c16..419b356 100644
--- a/src/java/com/jogamp/common/util/Bitstream.java
+++ b/src/java/com/jogamp/common/util/Bitstream.java
@@ -1166,11 +1166,9 @@ public class Bitstream<T> {
* Return incoming int32 as read via {@link #readBits31(boolean, int)}
* and swap bytes if !bigEndian.
* <p>
- * In case the returned value shall be interpreted as unsigned,
- * it shall be cast to <code>long</code> as follows:
- * <pre>
- * final long l = 0xffffffffL & int32;
- * </pre>
+ * In case the returned value shall be interpreted as <code>uint32_t</code>
+ * utilize {@link #toUint32Long(int)} or {@link #toUint32Int(int)} for
+ * an appropriate conversion.
* </p>
* @param msbFirst if true incoming stream bit order is MSB to LSB, otherwise LSB to MSB.
* @param bigEndian if false, swap incoming bytes to little-endian, otherwise leave them as little-endian.
@@ -1216,11 +1214,9 @@ public class Bitstream<T> {
* Return incoming int32 as read via {@link #readBits31(boolean, int)}
* and swap bytes if !bigEndian.
* <p>
- * In case the returned value shall be interpreted as unsigned,
- * it shall be cast to <code>long</code> as follows:
- * <pre>
- * final long l = 0xffffffffL & int32;
- * </pre>
+ * In case the returned value shall be interpreted as <code>uint32_t</code>
+ * utilize {@link #toUint32Long(int)} or {@link #toUint32Int(int)} for
+ * an appropriate conversion.
* </p>
* @param bigEndian if false, swap incoming bytes to little-endian, otherwise leave them as little-endian.
* @return the 32bit value, which might be unsigned or 2-complement signed value.
@@ -1303,6 +1299,32 @@ public class Bitstream<T> {
}
}
+ /**
+ * Reinterpret the given <code>int32_t</code> value as <code>uint32_t</code>,
+ * i.e. perform the following cast to <code>long</code>:
+ * <pre>
+ * final long l = 0xffffffffL & int32;
+ * </pre>
+ */
+ public static final long toUint32Long(final int val) {
+ return 0xffffffffL & val;
+ }
+
+ /**
+ * Returns the reinterpreted given <code>int32_t</code> value
+ * as <code>uint32_t</code> if &lt; {@link Integer#MAX_VALUE}
+ * as within an <code>int</code> storage.
+ * Otherwise return -1.
+ */
+ public static final int toUint32Int(final int val) {
+ final long v = toUint32Long(val);
+ if( v > Integer.MAX_VALUE ) {
+ return -1;
+ } else {
+ return (int)v;
+ }
+ }
+
public String toString() {
return String.format("Bitstream[%s]", toStringImpl());
}