aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/com/jogamp/common/util
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2014-02-21 07:31:12 +0100
committerSven Gothel <[email protected]>2014-02-21 07:31:12 +0100
commitc70c730b22c847668cf475dc6f841b85297ac3ab (patch)
treea2fe4b3d4f375e9ac3625c8c3ac4724257c3e7ba /src/java/com/jogamp/common/util
parent8022ae51a072f5198409d3c81d9979456676d0cf (diff)
Bitstream: Add static 'long toUint32Long(int)' and 'int toUint32Int(int)' conversion functions
Diffstat (limited to 'src/java/com/jogamp/common/util')
-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());
}