Here you can find the source of bytes2Bin(byte[] bytes)
static String bytes2Bin(byte[] bytes)
//package com.java2s; //License from project: Apache License public class Main { static String bytes2Bin(byte[] bytes) { StringBuilder sb = new StringBuilder(); for (byte b : bytes) { for (int i = 0; i < 8; i++) { sb.append(bitAt(b, i));/* w w w .ja va 2 s . co m*/ } } return sb.toString(); } static int bitAt(byte b, int pos) { int i = 1 << 7 - pos; return (b & i & 0xFF) > 0 ? 1 : 0; } }