Java Hex Calculate toHexaString(int value)

Here you can find the source of toHexaString(int value)

Description

Returns a string representation of the integer argument as an unsigned integer in base 16.

License

Open Source License

Declaration

public static String toHexaString(int value) 

Method Source Code

//package com.java2s;
/*/*www  .  j av  a 2s . c om*/
 * Copyright 2010, 2011 Institut Pasteur.
 * 
 * This file is part of ICY.
 * 
 * ICY is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * ICY is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with ICY. If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    /**
     * Returns a string representation of the integer argument as an
     * unsigned integer in base 16.
     */
    public static String toHexaString(int value) {
        return Integer.toHexString(value);
    }

    /**
     * Returns a string representation of the integer argument as an
     * unsigned integer in base 16.<br>
     * Force the returned string to have the specified size :<br>
     * If the string is longer then only last past is kept.<br>
     * If the string is shorter then leading 0 are added to the string.
     */
    public static String toHexaString(int value, int size) {
        String result = Integer.toHexString(value);

        if (result.length() > size)
            return result.substring(result.length() - size);

        while (result.length() < size)
            result = "0" + result;
        return result;
    }
}

Related

  1. toHexadecimal(final byte[] in)
  2. toHexadecimal(final byte[] message)
  3. toHexadecimealString(byte[] data, int length, boolean uppercase)
  4. toHexArray(byte[] binary)
  5. toHexaString(byte[] data)
  6. toHexByte(byte b)
  7. toHexByte(byte b, StringBuffer sb)
  8. toHexByte(final char ch1, final char ch2)
  9. toHexByte(int bite)