// Collection of code snippets by Arne VajhÃ¸j 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.io.UnsupportedEncodingException;

public class X2Bin {
    public static String toBin(byte b) {
        String res = Integer.toBinaryString(b & 0xFF);
        res = "00000000".substring(res.length()) + res;
        return res;
    }
    public static String toBin(byte[] b) {
        StringBuffer sb = new StringBuffer("");
        for(int i = 0; i < b.length; i++) {
            sb.append(toBin(b[i]));
        }
        return sb.toString();
    }
    public static String toBin(String s) throws UnsupportedEncodingException {
        return toBin(s.getBytes("ISO8859-1"));
    }
    public static void main(String[] args) throws Exception {
        System.out.println(X2Bin.toBin("testæøå"));
    }
}
