From b42f164c38624d00c71ac3d3d9ef55269de3426d Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 14 Nov 2008 00:13:13 +0100 Subject: [PATCH] Add method to format hexadecimal numbers. --- src/net/pterodactylus/util/number/Hex.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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(); + } + } -- 2.7.4