Java ASCII to Binary AsciiToBinary(String asciiString)

Here you can find the source of AsciiToBinary(String asciiString)

Description

Ascii To Binary

License

Open Source License

Declaration

public static String AsciiToBinary(String asciiString) 

Method Source Code

//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();
    }
}

Related

  1. ascii2bin(byte[] ascii, int offset, int len, byte[] binary)
  2. asciiToRawQuality(char quality)