Java Hex Calculate toHexString(byte value)

Here you can find the source of toHexString(byte value)

Description

to Hex String

License

Apache License

Declaration

public static String toHexString(byte value) 

Method Source Code

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

public class Main {

    public static String toHexString(byte value) {
        StringBuilder builder = new StringBuilder();
        String hex = Integer.toHexString(value & 0xff);
        if (hex.length() < 2) {
            builder.append("0");
        }//from  ww  w.ja  v  a 2  s  .c  om
        builder.append(hex);
        return builder.toString();
    }

    public static String toHexString(short value) {
        StringBuilder builder = new StringBuilder();
        String hex = Integer.toHexString(value & 0xffff);
        if (hex.length() < 4) {
            builder.append("000".substring(0, 4 - hex.length()));
        }
        builder.append(hex);
        return builder.toString();
    }
}

Related

  1. toHexString(byte bytes[])
  2. toHexString(byte data[])
  3. toHexString(byte input[])
  4. toHexString(byte n)
  5. toHexString(byte value)
  6. toHexString(byte[] arr)
  7. toHexString(byte[] array)
  8. toHexString(byte[] array)
  9. toHexString(byte[] b)