Java Hex Calculate toHexString(byte[] byteArray)

Here you can find the source of toHexString(byte[] byteArray)

Description

to Hex String

License

Open Source License

Declaration

public static String toHexString(byte[] byteArray) 

Method Source Code

//package com.java2s;
/*//w w  w . j ava 2s  .c o m
Copyright (C) 2013  Tobias B
    
    
    
odify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
    
jsync is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
    
You should have received a copy of the GNU General Public License
along with jsync.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    public static String toHexString(byte[] byteArray) {
        final StringBuilder ret = new StringBuilder();
        for (final byte b : byteArray) {
            ret.append(toHexString(b));
        }
        return ret.toString();
    }

    private static String toHexString(byte b) {
        return Character.toString(toHexChar((b & 0xFF) >> 4)) + Character.toString(toHexChar(b & 0x0F));
    }

    private static char toHexChar(int nibble) {
        if (nibble < 10) {
            return (char) ('0' + nibble);
        } else {
            return (char) ('A' + nibble - 10);
        }
    }
}

Related

  1. toHexString(byte[] buffer)
  2. toHexString(byte[] byteArray)
  3. toHexString(byte[] byteArray)
  4. toHexString(byte[] byteArray)
  5. toHexString(byte[] byteArray)
  6. toHexString(byte[] byteArray, boolean withSpaces)
  7. toHexString(byte[] byteArray, int offset, int size)
  8. toHexString(byte[] byteArray, String delim)
  9. toHexString(byte[] byteDigest)