From c70c730b22c847668cf475dc6f841b85297ac3ab Mon Sep 17 00:00:00 2001
From: Sven Gothel
- * In case the returned value shall be interpreted as unsigned,
- * it shall be cast to long
as follows:
- *
- * final long l = 0xffffffffL & int32;
- *
+ * In case the returned value shall be interpreted as uint32_t
+ * utilize {@link #toUint32Long(int)} or {@link #toUint32Int(int)} for
+ * an appropriate conversion.
*
- * In case the returned value shall be interpreted as unsigned,
- * it shall be cast to long
as follows:
- *
- * final long l = 0xffffffffL & int32; - *+ * In case the returned value shall be interpreted as
uint32_t
+ * utilize {@link #toUint32Long(int)} or {@link #toUint32Int(int)} for
+ * an appropriate conversion.
*
* @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 Bitstreamint32_t
value as uint32_t
,
+ * i.e. perform the following cast to long
:
+ * + * final long l = 0xffffffffL & int32; + *+ */ + public static final long toUint32Long(final int val) { + return 0xffffffffL & val; + } + + /** + * Returns the reinterpreted given
int32_t
value
+ * as uint32_t
if < {@link Integer#MAX_VALUE}
+ * as within an int
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());
}
--
cgit v1.2.3