diff --git a/Source/com/drew/metadata/bmp/BmpHeaderDescriptor.java b/Source/com/drew/metadata/bmp/BmpHeaderDescriptor.java index 5b85905b0..c0a1379b6 100644 --- a/Source/com/drew/metadata/bmp/BmpHeaderDescriptor.java +++ b/Source/com/drew/metadata/bmp/BmpHeaderDescriptor.java @@ -143,7 +143,12 @@ public static String formatHex(@Nullable Long value, int digits) { @NotNull public static String formatHex(long value, int digits) { - return String.format("0x%0"+ digits + "X", value); + StringBuilder sb = new StringBuilder(); + sb.append("0x"); + long maskedValue = value & ((1L << (digits * 4)) - 1); + int leadingZeros = Long.numberOfLeadingZeros(maskedValue) >> 2; + sb.append(Long.toHexString(maskedValue | (1L << (digits * 4))).substring(leadingZeros)); + return sb.toString(); } @Nullable