Here you can find the source of integerToHexString(int value, int minBytes)
Parameter | Description |
---|---|
value | The integer value to convert to hexadecimal string. |
minBytes | The minimum number of bytes to be represented. |
Parameter | Description |
---|---|
IllegalArgumentException | if minBytes <= 0. |
public static String integerToHexString(int value, int minBytes)
//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); } }