Java Hex Calculate toHex(long i, int r0, boolean r1)

Here you can find the source of toHex(long i, int r0, boolean r1)

Description

Converts a number to a hex value

License

Open Source License

Parameter

Parameter Description
i The value
r1 Should the string be fancy? (0xYYYY)
r0 Length of fancieness

Return

The string

Declaration

public static String toHex(long i, int r0, boolean r1) 

Method Source Code

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

public class Main {
    /**/*from w  w w .  ja va  2s.com*/
     * Converts a number to a hex value
     *
     * @param i  The value
     * @param r1 Should the string be fancy? (0xYYYY)
     * @param r0 Length of fancieness
     * @return The string
     */
    public static String toHex(long i, int r0, boolean r1) {
        String h = Long.toHexString(i).toUpperCase();
        while (h.length() < r0 && r1) {
            h = 0 + h;
        }

        return (r1 ? "0x" : "") + h;
    }

    public static String toHex(long i) {
        return toHex(i, 2, false);
    }
}

Related

  1. toHex(int value, int bits)
  2. toHex(int value, int length)
  3. toHex(int value, int length)
  4. toHex(int value, int minNumOfDigits)
  5. toHex(long i)
  6. toHex(long l, int length)
  7. toHex(Long value, int charCount)
  8. toHex(long value, int length)
  9. toHex(String color)