Here you can find the source of toHexWithMarker(byte b)
Parameter | Description |
---|---|
b | byte |
static public String toHexWithMarker(byte b)
//package com.java2s; /**//from w w w . j a v a 2s .co m * Copyright (C) 2008 ITS of ETH Zurich, Switzerland, Sarah Windler Burri * <p> * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 3 of the License, or (at your option) any * later version. * <p> * 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. * <p> * See the GNU Lesser General Public License for more details. You should have * received a copy of the GNU Lesser General Public License along with this * program; if not, see <http://www.gnu.org/licenses/>. */ public class Main { /** * @param b byte * @return String with Marker '0x' ahead */ static public String toHexWithMarker(byte b) { StringBuilder sb = new StringBuilder(); sb.append("0x").append(toHex(b)); return sb.toString(); } /** * @param b byte * @return String */ static public String toHex(byte b) { String st = Integer.toHexString(b); return (st.length() == 1) ? "0" + st : st; } /** * @param dst array of byte * @return String representation */ static String toString(byte[] dst) { int l = dst.length; StringBuilder sb = new StringBuilder(l); for (int i = 0; i < l; i++) { int b = dst[i]; int ival = ((int) b) & 0xff; char c = (char) ival; sb.append(c); } return sb.toString(); } }