Here you can find the source of byteToString(byte b)
public static String byteToString(byte b)
//package com.java2s; /*/* ww w . j av a 2 s . c o m*/ (c) Copyright 2004, 2005 Gary Dusbabek gdusbabek@gmail.com ALL RIGHTS RESERVED. By using this software, you acknowlege and agree that: 1. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 2. This product may be freely copied and distributed in source or binary form given that the license (this file) and any copyright declarations remain in tact. The End */ public class Main { public static String byteToString(byte b) { String s = "0x"; for (int i = 0; i < 8; i++) { if ((b & (1 << 7 - i)) > 0) s += "1"; else s += "0"; } return s; } }