Java Byte to String byteToString(int n)

Here you can find the source of byteToString(int n)

Description

Returns a string of 2 hexadecimal digits (most significant digit first) corresponding to the lowest 8 bits of n.

License

Open Source License

Parameter

Parameter Description
n the byte value to convert.

Return

a string of 2 hex characters representing the input.

Declaration

public static String byteToString(int n) 

Method Source Code

//package com.java2s;
// it under the terms of the GNU General Public License as published by

public class Main {
    private static final char[] HEX_DIGITS = "0123456789ABCDEF".toCharArray();

    /**//from  w w w  .j a va 2  s.  co  m
     * <p>Returns a string of 2 hexadecimal digits (most significant digit first)
     * corresponding to the lowest 8 bits of <code>n</code>.</p>
     *
     * @param n the byte value to convert.
     * @return a string of 2 hex characters representing the input.
     */
    public static String byteToString(int n) {
        char[] buf = { HEX_DIGITS[(n >>> 4) & 0x0F], HEX_DIGITS[n & 0x0F] };
        return new String(buf);
    }
}

Related

  1. byteToString(int b)
  2. ByteToString(int b)
  3. byteToString(int b)
  4. byteToString(int b)
  5. byteToString(int n)
  6. byteToString(int val)