Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
comments
  • Loading branch information
yaooqinn committed Jun 27, 2024
commit 2544a844dcab691e89745c48d1c1a4c72b1c657f
Original file line number Diff line number Diff line change
Expand Up @@ -1869,18 +1869,21 @@ public void read(Kryo kryo, Input in) {
in.read((byte[]) base);
}

/**
* Convert a long value to its binary format stripping leading zeros.
*/
public static UTF8String toBinaryString(long val) {
int zeros = Long.numberOfLeadingZeros(val);
if (zeros == Long.SIZE) {
return UTF8String.ZERO_UTF8;
} else {
int length = Math.max(Long.SIZE - Long.numberOfLeadingZeros(val), 1);
byte[] buf = new byte[length];
int length = Long.SIZE - Long.numberOfLeadingZeros(val);
byte[] bytes = new byte[length];
do {
buf[--length] = (byte) ((val & 0x1) == 1 ? '1': '0');
bytes[--length] = (byte) ((val & 0x1) == 1 ? '1': '0');
val >>>= 1;
} while(length > 0);
return fromBytes(buf);
} while (length > 0);
return fromBytes(bytes);
}
}
}