Here you can find the source of AsciiToBinary(String asciiString)
public static String AsciiToBinary(String asciiString)
//package com.java2s; //License from project: Open Source License public class Main { public static String AsciiToBinary(String asciiString) { byte[] bytes = asciiString.getBytes(); StringBuilder binary = new StringBuilder(); for (byte b : bytes) { int val = b; for (int i = 0; i < 8; i++) { binary.append((val & 128) == 0 ? 0 : 1); val <<= 1; }//from w w w.j a v a 2 s . c o m // binary.append(' '); } return binary.toString(); } }