Here you can find the source of toHexString(byte[] bytes)
Parameter | Description |
---|---|
bytes | The array of bytes to convert to ASCII hex form. |
public static final String toHexString(byte[] bytes)
//package com.java2s; /******************************************************************************* * Copyright (c) 2004, 2005 Sybase, Inc. and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:// w w w .j a v a 2 s.c o m * Sybase, Inc. - initial API and implementation *******************************************************************************/ public class Main { private static final char[] HexChars = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; /** * @param bytes The array of bytes to convert to ASCII hex form. * @return An ASCII hexadecimal numeric string representing the * specified array of bytes. */ public static final String toHexString(byte[] bytes) { StringBuffer sb = new StringBuffer(); sb.append("0x"); int i; for (i = 0; i < bytes.length; i++) { sb.append(HexChars[(bytes[i] >> 4) & 0xf]); sb.append(HexChars[bytes[i] & 0xf]); } return new String(sb); } }