X-Git-Url: https://git.pterodactylus.net/?p=jSite2.git;a=blobdiff_plain;f=src%2Fnet%2Fpterodactylus%2Futil%2Fnumber%2FHex.java;h=246fa419138b61cd21c2946402775aa29d83feab;hp=f81ec05d5abe0b7ff30404fd090739e32033349a;hb=b42f164c38624d00c71ac3d3d9ef55269de3426d;hpb=587bc80b5c501f76b19890370810bb76bd6b55d6 diff --git a/src/net/pterodactylus/util/number/Hex.java b/src/net/pterodactylus/util/number/Hex.java index f81ec05..246fa41 100644 --- a/src/net/pterodactylus/util/number/Hex.java +++ b/src/net/pterodactylus/util/number/Hex.java @@ -42,4 +42,23 @@ public class Hex { return hexString.toString(); } + /** + * Converts the given value to a hexadecimal string and zero-pads it to the + * given number of digits. + * + * @param value + * The value to convert + * @param digits + * The number of digits + * @return The formatted hexadecimal value + */ + public static String toHex(long value, int digits) { + StringBuilder hexString = new StringBuilder(); + hexString.append(Long.toHexString(value)); + while (hexString.length() < digits) { + hexString.insert(0, '0'); + } + return hexString.toString(); + } + }