Here you can find the source of toHex(byte b)
Parameter | Description |
---|---|
b | The byte to be converted to a string. |
public static String toHex(byte b)
//package com.java2s; /*//from ww w . j a v a 2 s . c o m * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies). * All rights reserved. * This component and the accompanying materials are made available * under the terms of "Eclipse Public License v1.0" * which accompanies this distribution, and is available * at the URL "http://www.eclipse.org/legal/epl-v10.html". * * Initial Contributors: * Nokia Corporation - initial contribution. * * Contributors: * * Description: Helper class containing common non-HTI-specific helper * functions that can be used in other java classes. * */ public class Main { /** * Renders a given by to nice human readable hex format. * * @param b The byte to be converted to a string. * @return The result as a string, in the format 0x00. */ public static String toHex(byte b) { StringBuffer sb = new StringBuffer(4); sb.append("0x"); int val = b & 0xff; if (val < 0x10) sb.append("0"); sb.append(Integer.toString(val, 16)); return sb.toString(); } }