public class Test { public static void main(String args[]) { String ZERO="00000000"; String x ="lalala"; byte[] bs = x.getBytes(); for (int i = 0;i<bs.length;i++) { String s = Integer.toBinaryString(bs[i]); if (s.length() > 8) { s = s.substring(s.length() - 8); } else if (s.length() < 8) { s = ZERO.substring(s.length()) + s; } System.out.println(s); } } }