String str = "Rama" byte[] b = str.getBytes() byte b1 = (byte) 129; String s1 = String.format("%8s", Integer.toBinaryString(b1 & 0xFF)).replace(' ', '0'); System.out.println(s1);