mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-11-02 05:27:17 +00:00
Utils: Comment and harmonize the various methods for reading ints.
This commit is contained in:
@@ -184,35 +184,40 @@ public class Utils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return rev;
|
return rev;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Parse 4 bytes from the byte array (starting at the offset) as unsigned 32-bit integer in little endian format. */
|
||||||
public static long readUint32(byte[] bytes, int offset) {
|
public static long readUint32(byte[] bytes, int offset) {
|
||||||
return (bytes[offset++] & 0xFFL) |
|
return (bytes[offset] & 0xffl) |
|
||||||
((bytes[offset++] & 0xFFL) << 8) |
|
((bytes[offset + 1] & 0xffl) << 8) |
|
||||||
((bytes[offset++] & 0xFFL) << 16) |
|
((bytes[offset + 2] & 0xffl) << 16) |
|
||||||
((bytes[offset] & 0xFFL) << 24);
|
((bytes[offset + 3] & 0xffl) << 24);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Parse 8 bytes from the byte array (starting at the offset) as signed 64-bit integer in little endian format. */
|
||||||
public static long readInt64(byte[] bytes, int offset) {
|
public static long readInt64(byte[] bytes, int offset) {
|
||||||
return (bytes[offset++] & 0xFFL) |
|
return (bytes[offset] & 0xffl) |
|
||||||
((bytes[offset++] & 0xFFL) << 8) |
|
((bytes[offset + 1] & 0xffl) << 8) |
|
||||||
((bytes[offset++] & 0xFFL) << 16) |
|
((bytes[offset + 2] & 0xffl) << 16) |
|
||||||
((bytes[offset++] & 0xFFL) << 24) |
|
((bytes[offset + 3] & 0xffl) << 24) |
|
||||||
((bytes[offset++] & 0xFFL) << 32) |
|
((bytes[offset + 4] & 0xffl) << 32) |
|
||||||
((bytes[offset++] & 0xFFL) << 40) |
|
((bytes[offset + 5] & 0xffl) << 40) |
|
||||||
((bytes[offset++] & 0xFFL) << 48) |
|
((bytes[offset + 6] & 0xffl) << 48) |
|
||||||
((bytes[offset] & 0xFFL) << 56);
|
((bytes[offset + 7] & 0xffl) << 56);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Parse 4 bytes from the byte array (starting at the offset) as unsigned 32-bit integer in big endian format. */
|
||||||
public static long readUint32BE(byte[] bytes, int offset) {
|
public static long readUint32BE(byte[] bytes, int offset) {
|
||||||
return ((bytes[offset] & 0xFFL) << 24) |
|
return ((bytes[offset] & 0xffl) << 24) |
|
||||||
((bytes[offset + 1] & 0xFFL) << 16) |
|
((bytes[offset + 1] & 0xffl) << 16) |
|
||||||
((bytes[offset + 2] & 0xFFL) << 8) |
|
((bytes[offset + 2] & 0xffl) << 8) |
|
||||||
(bytes[offset + 3] & 0xFFL);
|
(bytes[offset + 3] & 0xffl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Parse 2 bytes from the byte array (starting at the offset) as unsigned 16-bit integer in big endian format. */
|
||||||
public static int readUint16BE(byte[] bytes, int offset) {
|
public static int readUint16BE(byte[] bytes, int offset) {
|
||||||
return ((bytes[offset] & 0xff) << 8) | bytes[offset + 1] & 0xff;
|
return ((bytes[offset] & 0xff) << 8) |
|
||||||
|
(bytes[offset + 1] & 0xff);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user