4 namespace org { namespace ldk { namespace util {
7 * A 5-bit unsigned integer
11 public UInt5(byte val) {
12 if (val > 32 || val < 0) {
13 throw new ArgumentException();
19 * @return the value represented
21 public byte getVal() {
27 * A 5-bit unsigned integer
29 public class UInt128 {
30 private byte[] le_bytes;
33 * Constructs a 128-bit integer from its little-endian representation
35 public UInt128(byte[] le_bytes) {
36 if (le_bytes.Length != 16) {
37 throw new ArgumentException();
39 this.le_bytes = le_bytes;
43 * Constructs a 128-bit integer from a long, ignoring the sign bit
45 public UInt128(long val) {
46 byte[] le_bytes = new byte[16];
47 for (int i = 0; i < 8; i++)
48 le_bytes[i] = (byte) ((val >> i*8) & 0xff);
49 this.le_bytes = le_bytes;
53 * @return The value as 16 little endian bytes
55 public byte[] getLEBytes() { return le_bytes; }
57 public override bool Equals(object o) {
58 if (o == null || !(o is UInt128)) return false;
59 byte[] o_le_bytes = ((UInt128) o).le_bytes;
60 return le_bytes.SequenceEqual(o_le_bytes);
63 public override int GetHashCode() { return le_bytes.GetHashCode(); }