Java tutorial
//package com.java2s; //PduUtils is distributed under the terms of the Apache License version 2.0 public class Main { public static String pduToBits(String pduString) { return bytesToBits(pduToBytes(pduString)); } public static String bytesToBits(byte[] b) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < b.length; i++) { String bits = Integer.toBinaryString(b[i] & 0xFF); while (bits.length() < 8) { bits = "0" + bits; } if (i > 0) { sb.append(" "); } sb.append(bits); } return sb.toString(); } public static byte[] pduToBytes(String s) { byte[] bytes = new byte[s.length() / 2]; for (int i = 0; i < s.length(); i += 2) { bytes[i / 2] = (byte) (Integer.parseInt(s.substring(i, i + 2), 16)); } return bytes; } }