Java Hex Calculate toHex16(int w)

Here you can find the source of toHex16(int w)

Description

to Hex

License

Open Source License

Declaration

public static String toHex16(int w) 

Method Source Code

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

public class Main {
    public static String toHex16(int w) {
        return toHex((byte) (0xff & (w >> 8))) + toHex((byte) (0xff & w));
    }// w  w  w.  j a  v a2  s  .  co  m

    public static String toHex(byte b) {
        String s;
        int iByte = b & 0xff;

        if (iByte < 16) {
            s = "0" + Integer.toHexString(iByte);
        } else {
            s = Integer.toHexString(iByte);
        }

        return s.toUpperCase();
    }

    public static String toHex(byte[] data) {
        return toHex(data, data.length);
    }

    public static String toHex(byte[] data, int size) {
        return toHex(data, 0, size);
    }

    public static String toHex(byte[] data, int start, int size) {
        StringBuffer sb = new StringBuffer();
        int count = 0;
        for (int i = 0; i < size; i++) {
            byte b = data[start + i];
            if (++count > size) {
                break;
            }
            if (sb.length() > 0) {
                sb.append(' ');
            }

            sb.append(toHex(b));
        }

        return sb.toString();
    }
}

Related

  1. toHex(String val)
  2. toHex(StringBuffer buf, long value, int width)
  3. toHex(StringBuilder s, byte b)
  4. toHex00String(int c)
  5. toHEX1(byte b)
  6. toHex16(long l)
  7. toHex4(int value)
  8. toHex8(long x)
  9. toHexa(byte[] bb)