Java Hex Calculate toHex(byte b)

Here you can find the source of toHex(byte b)

Description

to Hex

License

Open Source License

Declaration

public static String toHex(byte b) 

Method Source Code

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

public class Main {
    public static String toHex(byte b) {
        b += 0x80;/*from www. j  a v a 2  s  .com*/
        int hb = (b & 0xF0) >> 4;
        int lb = b & 0x0F;
        return toHex(hb) + toHex(lb);
    }

    public static String toHex(int half_byte) {
        if (half_byte > 15 || half_byte < 0)
            return null;
        if (half_byte < 10) {
            return String.valueOf(half_byte);
        } else {
            switch (half_byte) {
            case (10):
                return "A";
            case (11):
                return "B";
            case (12):
                return "C";
            case (13):
                return "D";
            case (14):
                return "E";
            case (15):
                return "F";
            default:
                return null;
            }
        }
    }
}

Related

  1. toHex(boolean[] bits)
  2. toHex(byte b)
  3. toHex(byte b)
  4. tohex(byte b)
  5. toHex(byte b)