日期:2014-05-20 浏览次数:20664 次
public class StrtoBin { public static void main(String[] args) { String str = "我是"; byte[] b = str.getBytes(); StringBuffer sb = new StringBuffer(); for(int i = 0; i < b.length; i++) { sb.append(byteBin(b[i])); } System.out.println(sb.toString()); } public static String byteBin(byte ib) { char[] Digit = {'0', '1'}; char[] bin = new char[8]; for(int i = 0; i < bin.length; i++) { bin[i] = Digit[(ib>>(7-i)) & 0X01]; } return new String(bin); } }