Android Byte Array to String Convert convertBytesToString(byte[] value)

Here you can find the source of convertBytesToString(byte[] value)

Description

Convert a byte array to a hex encoded string.

License

Open Source License

Parameter

Parameter Description
value the byte array

Return

the hex encoded string

Declaration

public static String convertBytesToString(byte[] value) 

Method Source Code

//package com.java2s;
/*// www . ja v a2s.  co  m
 * Copyright 2004-2008 H2 Group. Multiple-Licensed under the H2 License, Version 1.0, and under the Eclipse Public License, Version 1.0 (http://h2database.com/html/license.html). Initial Developer: H2 Group
 */

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

    /**
     * Convert a byte array to a hex encoded string.
     * 
     * @param value
     *          the byte array
     * @return the hex encoded string
     */
    public static String convertBytesToString(byte[] value) {
        return convertBytesToString(value, value.length);
    }

    /**
     * Convert a byte array to a hex encoded string.
     * 
     * @param value
     *          the byte array
     * @param len
     *          the number of bytes to encode
     * @return the hex encoded string
     */
    public static String convertBytesToString(byte[] value, int len) {
        char[] buff = new char[len + len];
        char[] hex = HEX;
        for (int i = 0; i < len; i++) {
            int c = value[i] & 0xff;
            buff[i + i] = hex[c >> 4];
            buff[i + i + 1] = hex[c & 0xf];
        }
        return new String(buff);
    }
}

Related

  1. getString(byte[] originalByte, int start, int length)
  2. getString(byte[] value)
  3. getStringByByteArray(byte[] b)
  4. toByteString(byte[] bytes)
  5. toByteString(byte[] bytes, int start, int length)
  6. convertBytesToString(byte[] value, int len)
  7. byteTOString(byte[] in)
  8. byteTOString(byte[] in)
  9. byteTOString(byte[] in)