Java Hex Calculate toHexString(int iValue)

Here you can find the source of toHexString(int iValue)

Description

to Hex String

License

Apache License

Declaration

static public String toHexString(int iValue) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    static public String toHexString(byte[] bytes) {
        StringBuffer strBuffer = new StringBuffer(50);
        for (int i = 0; i < bytes.length; i++)
            strBuffer.append(toHexString(bytes[i]));
        return strBuffer.toString();
    }/*from   w ww  .j  a  v a 2 s  .  c om*/

    static public String toHexString(int iValue) {
        String str = Integer.toHexString(iValue);
        if (str.length() == 1)
            return "0" + str;
        /**
         * if iValue >= 128, it will return ffffff80, we need to cut off first 6 digits
         * only get last two digits
         */
        else if (str.length() == 8)
            return str.substring(6, 8);
        return str;
    }
}

Related

  1. toHexString(int i)
  2. toHexString(int i)
  3. toHexString(int i)
  4. toHexString(int i, int digits)
  5. toHexString(int input)
  6. toHexString(int n)
  7. toHexString(int number, int digit)
  8. toHexString(int r, int g, int b, int a)
  9. toHexString(int val)