Java Byte to String byteToString(byte b)

Here you can find the source of byteToString(byte b)

Description

byte To String

License

Open Source License

Declaration

public static String byteToString(byte b) 

Method Source Code

//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;
    }
}

Related

  1. byteToArrayString(byte bByte)
  2. byteToStr(byte input)
  3. byteToString(byte b)
  4. byteToString(byte b)
  5. ByteToString(byte b)
  6. byteToString(byte b_)