Java Integer to Hex integerToHexString(int value, int minBytes)

Here you can find the source of integerToHexString(int value, int minBytes)

Description

Converts the given integer into an hexadecimal string.

License

Mozilla Public License

Parameter

Parameter Description
value The integer value to convert to hexadecimal string.
minBytes The minimum number of bytes to be represented.

Exception

Parameter Description
IllegalArgumentException if minBytes <= 0.

Return

The integer value as hexadecimal string.

Declaration

public static String integerToHexString(int value, int minBytes) 

Method Source Code

//package com.java2s;
/**//w w  w . java 2 s  . c om
 * Copyright (c) 2014-2016 Digi International Inc.,
 * All rights not expressly granted are reserved.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
 * =======================================================================
 */

public class Main {
    /**
     * Converts the given integer into an hexadecimal string.
     * 
     * @param value The integer value to convert to hexadecimal string.
     * @param minBytes The minimum number of bytes to be represented.
     * 
     * @return The integer value as hexadecimal string.
     * 
     * @throws IllegalArgumentException if {@code minBytes <= 0}.
     */
    public static String integerToHexString(int value, int minBytes) {
        if (minBytes <= 0)
            throw new IllegalArgumentException("Minimum number of bytes must be greater than 0.");

        String f = String.format("%%0%dX", minBytes * 2);
        return String.format(f, value);
    }
}

Related

  1. integerToHex(final Object value, final int desimals)
  2. integerToHex(final Object value, final int desimals)
  3. integerToHex(int val)
  4. integerToHexShort(int value)
  5. integerToHexString(final int aValue, final int aFieldWidth)
  6. intToFixedLengthHex(int value, int length)
  7. intToFixedLengthHexString(int i, int length)
  8. intToHex(int a)
  9. intToHex(int i)