Java BigInteger to toEvenLengthHex(BigInteger value)

Here you can find the source of toEvenLengthHex(BigInteger value)

Description

Convert a big integer into hex string.

License

Mozilla Public License

Declaration

public static String toEvenLengthHex(BigInteger value) 

Method Source Code


//package com.java2s;
/* 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/. */

import java.math.BigInteger;

public class Main {
    /**//w  w  w . j a va 2  s.  c  om
     * Convert a big integer into hex string. If the length is not even, add an
     * '0' character in the beginning to make it even.
     */
    public static String toEvenLengthHex(BigInteger value) {
        String result = value.toString(16);
        if (result.length() % 2 != 0) {
            result = "0" + result;
        }
        return result;
    }
}

Related

  1. toByteArray(final BigInteger value, final int numBytes)
  2. toByteArrayUnsigned(BigInteger bi)
  3. toBytes(BigInteger bigInt, int expectedSize)
  4. toBytesUnsigned(final BigInteger bigInt)
  5. toDecimal(BigInteger value, byte[] buffer, int offset, int length, int itemLength, byte pos)
  6. toFixedLenByteArray(BigInteger x, int resultByteLen)
  7. toInt(BigInteger number)
  8. toInt(int length, BigInteger bi)
  9. toIntArray(BigInteger[] input)