Java Hex Calculate toHex(byte[] a)

Here you can find the source of toHex(byte[] a)

Description

to Hex

License

Open Source License

Declaration

public static String toHex(byte[] a) 

Method Source Code

//package com.java2s;
/**//from   www .  j ava 2 s  . com
 *
 *  #%L
 *  geoserver-sync-core
 *  $Id:$
 *  $HeadURL:$
 *  %%
 *  Copyright (C) 2013 Moebius Solutions Inc.
 *  %%
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as
 *  published by the Free Software Foundation, either version 2 of the
 *  License, or (at your option) any later version.
 *
 *  This program 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 this program.  If not, see
 *  <http://www.gnu.org/licenses/gpl-2.0.html>.
 *  #L%
 *
 */

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

    public static String toHex(byte[] a) {
        char[] result = new char[2 * a.length];
        for (int i = 0; i < a.length; i++) {
            int high = (0xF0 & a[i]) >> 4;
            int low = (0x0F & a[i]);
            result[2 * i] = charMap[high];
            result[2 * i + 1] = charMap[low];
        }
        return new String(result);
    }
}

Related

  1. toHex(byte one)
  2. toHex(byte value)
  3. toHex(byte value)
  4. toHex(byte... bs)
  5. toHex(byte... bytes)
  6. toHex(byte[] address, StringBuilder builder)
  7. tohex(byte[] arg)
  8. toHex(byte[] arr)
  9. toHex(byte[] array)