Java Hex Calculate toHex(long value, int length)

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

Description

Converts a long value to an HEX string.

License

Open Source License

Parameter

Parameter Description
value The long value
length The length of the string

Return

The hex string

Declaration

public static String toHex(long value, int length) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//from  w  w  w.  j av  a2  s. c o  m
     * Converts a long value to an HEX string.<br>
     *
     * @param value
     *            The long value
     * @param length
     *            The length of the string
     * @return The hex string
     */
    public static String toHex(long value, int length) {
        return String.format("%0" + length + "X", value);
    }

    /**
     * Converts an float value to an HEX string.<br>
     *
     * @param value
     *            The float value
     * @param length
     *            The length of the string
     * @return The hex string
     */
    public static String toHex(float value, int length) {
        return toHex(convertFloatToHex(value), length);
    }

    /**
     * Convert a float value to a hex value given as a long.<br>
     *
     * @param floatValue
     *            The float value
     * @return The hex value
     */
    public static long convertFloatToHex(float floatValue) {
        return Float.floatToIntBits(floatValue) & 0xFFFFFFFFL;
    }
}

Related

  1. toHex(int value, int minNumOfDigits)
  2. toHex(long i)
  3. toHex(long i, int r0, boolean r1)
  4. toHex(long l, int length)
  5. toHex(Long value, int charCount)
  6. toHex(String color)
  7. toHex(String in, boolean javaStyle)
  8. toHEX(String ostr)
  9. toHex(String source)