Java Hex Calculate ToHexString(int value, int length)

Here you can find the source of ToHexString(int value, int length)

Description

Format an integer to its hex representaion, with (at least) the given number of digits, left padded with '0'

License

Open Source License

Declaration

public static String ToHexString(int value, int length) 

Method Source Code

//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;
    }
}

Related

  1. toHexString(int number, int digit)
  2. toHexString(int r, int g, int b, int a)
  3. toHexString(int val)
  4. toHexString(int val, int minLength)
  5. toHexString(int value, int len)
  6. toHexString(int value, int minLength)
  7. toHexString(int value, int numDigits)
  8. toHexString(int[] data)
  9. toHexString(int[] ia)