Here you can find the source of ToHexString(int value, int length)
public static String ToHexString(int value, int length)
//package com.java2s; public class Main { private static final String Zeroes = "0000000000000000000000000000000000000"; /**// w ww .j a v a 2 s . co m * Format an integer to its hex representaion, with (at least) the given number of digits, left padded with '0' */ public static String ToHexString(int value, int length) { String answer = Integer.toHexString(value).toUpperCase(); int currentLength = answer.length(); if (currentLength < length) { answer = Zeroes.substring(0, length - currentLength) + answer; } return answer; } }