Java Hex Calculate toHex(int value, int bits)

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

Description

Conversion pixel to HEX value

License

Open Source License

Parameter

Parameter Description
value pixel value
bits a parameter

Return

HEX presentation of pixel

Declaration

public static String toHex(int value, int bits) 

Method Source Code

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

public class Main {
    /**//from   w  w  w .  j  a  v a  2s.co m
     * Conversion pixel to HEX value
     * @param value pixel value
     * @param bits 
     * @return HEX presentation of pixel 
     */
    public static String toHex(int value, int bits) {

        String hex = Integer.toHexString(value);
        int padLen = 4 - hex.length();
        if (bits == 0) {
            padLen = 2 - hex.length();
        }
        for (int i = 0; i < padLen; i++) {
            hex = "0" + hex;
        }
        hex = "0x" + hex;
        return hex;
    }
}

Related

  1. toHex(int val)
  2. toHex(int val)
  3. toHEX(int value)
  4. toHex(int value)
  5. toHex(int value)
  6. toHex(int value, int length)
  7. toHex(int value, int length)
  8. toHex(int value, int minNumOfDigits)
  9. toHex(long i)