Here you can find the source of toHexStringBE(char[] array)
public static String toHexStringBE(char[] array)
//package com.java2s; /*-//from www.j a v a2 s.com * Copyright (C) 2006-2007 Erik Larsson * * 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 3 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/>. */ public class Main { public static String toHexStringBE(char[] array) { return toHexStringBE(array, 0, array.length); } public static String toHexStringBE(char[] array, int offset, int length) { StringBuilder result = new StringBuilder(); for (int i = offset; i < length; ++i) result.append(toHexStringBE(array[i])); return result.toString(); } public static String toHexStringBE(short[] array) { return toHexStringBE(array, 0, array.length); } public static String toHexStringBE(short[] array, int offset, int length) { StringBuilder result = new StringBuilder(); for (int i = offset; i < length; ++i) result.append(toHexStringBE(array[i])); return result.toString(); } public static String toHexStringBE(int[] array) { return toHexStringBE(array, 0, array.length); } public static String toHexStringBE(int[] array, int offset, int length) { StringBuilder result = new StringBuilder(); for (int i = offset; i < length; ++i) result.append(toHexStringBE(array[i])); return result.toString(); } public static String toHexStringBE(byte n) { return byteArrayToHexString(toByteArrayBE(n)); } public static String toHexStringBE(short n) { return byteArrayToHexString(toByteArrayBE(n)); } public static String toHexStringBE(char n) { return byteArrayToHexString(toByteArrayBE(n)); } public static String toHexStringBE(int n) { return byteArrayToHexString(toByteArrayBE(n)); } public static String toHexStringBE(long n) { return byteArrayToHexString(toByteArrayBE(n)); } public static String byteArrayToHexString(byte[] array) { return byteArrayToHexString(array, 0, array.length); } public static String byteArrayToHexString(byte[] array, int offset, int length) { String result = ""; for (int i = offset; i < (offset + length); ++i) { byte b = array[i]; String currentHexString = Integer.toHexString(b & 0xFF); if (currentHexString.length() == 1) currentHexString = "0" + currentHexString; result += currentHexString; } return result; } public static byte[] toByteArrayBE(byte b) { byte[] result = new byte[1]; result[0] = b; return result; } public static byte[] toByteArrayBE(short s) { byte[] result = new byte[2]; result[0] = (byte) ((s >> 8) & 0xFF); result[1] = (byte) ((s >> 0) & 0xFF); return result; } public static byte[] toByteArrayBE(char c) { byte[] result = new byte[2]; result[0] = (byte) ((c >> 8) & 0xFF); result[1] = (byte) ((c >> 0) & 0xFF); return result; } public static byte[] toByteArrayBE(int i) { byte[] result = new byte[4]; result[0] = (byte) ((i >> 24) & 0xFF); result[1] = (byte) ((i >> 16) & 0xFF); result[2] = (byte) ((i >> 8) & 0xFF); result[3] = (byte) ((i >> 0) & 0xFF); return result; } public static byte[] toByteArrayBE(long l) { byte[] result = new byte[8]; result[0] = (byte) ((l >> 56) & 0xFF); result[1] = (byte) ((l >> 48) & 0xFF); result[2] = (byte) ((l >> 40) & 0xFF); result[3] = (byte) ((l >> 32) & 0xFF); result[4] = (byte) ((l >> 24) & 0xFF); result[5] = (byte) ((l >> 16) & 0xFF); result[6] = (byte) ((l >> 8) & 0xFF); result[7] = (byte) ((l >> 0) & 0xFF); return result; } }