Java Hex Calculate toHEX(int value)

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

Description

to HEX

License

Open Source License

Declaration

public static String toHEX(int value) 

Method Source Code

//package com.java2s;
/*/*from   ww  w. java  2 s .co  m*/
 * This program 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.
 */

public class Main {
    public static String toHEX(int value) {
        return toHEX(value, 4);
    }

    public static String toHEX(int value, int count) {
        StringBuffer buf = new StringBuffer();
        String hex = Integer.toHexString(value);

        int hlen = hex.length();
        while (count > hlen) {
            buf.append("0");
            count--;
        }

        buf.append(hex.toUpperCase());
        return buf.toString();
    }
}

Related

  1. toHex(int r, int g, int b)
  2. toHex(int v)
  3. toHex(int val)
  4. toHex(int val)
  5. toHex(int value)
  6. toHex(int value)
  7. toHex(int value, int bits)
  8. toHex(int value, int length)
  9. toHex(int value, int length)