Java Hex Calculate toHexFromByte(byte b)

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

Description

Converts byte to hex string.

License

Apache License

Parameter

Parameter Description
b byte to be converted to hex string

Return

hex string

Declaration

public static final StringBuilder toHexFromByte(byte b) 

Method Source Code

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

public class Main {
    private static final String[] hexSymbols = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c",
            "d", "e", "f" };

    /***//from   w ww.  j  a  va2s.c o  m
     * Converts byte to hex string.
     * 
     * @param b
     *            byte to be converted to hex string
     * @return hex string
     */
    public static final StringBuilder toHexFromByte(byte b) {
        byte leftSymbol = (byte) (b >>> 4 & 0xF);
        byte rightSymbol = (byte) (b & 0xF);
        return new StringBuilder(hexSymbols[leftSymbol] + hexSymbols[rightSymbol]);
    }
}

Related

  1. toHexDump(byte[] buffer, int offset, int length, boolean hex, boolean ascii)
  2. toHexDump(byte[] bytes)
  3. toHexEscape(final int u0)
  4. toHexFilter(String inAscii)
  5. toHexFromBin(final String binSymbols)
  6. toHexFromByte(final byte b)
  7. toHexFromBytes(byte[] bytes)
  8. toHexFromBytes(final byte[] bytes)
  9. toHexFromOct(final String octSymbols)