Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) {
- System.out.println(doIt(new byte[] {1} ));
- System.out.println(doIt(new byte[] {2} ));
- System.out.println(doIt(new byte[] {1,1} ));
- System.out.println(doIt(new byte[] {1,2} ));
- }
- public static String paddLeft(String source, char padding, int length) {
- StringBuilder sb = new StringBuilder();
- sb.append(source);
- while(sb.length() < length) {
- sb.insert(0, padding);
- }
- return sb.toString();
- }
- public static String convertToString(int number) {
- return Integer.toBinaryString(number);
- }
- public static String doIt(byte[] bytes) {
- StringBuilder sb = new StringBuilder();
- for(byte b : bytes) {
- sb.append(paddLeft(convertToString(b), '0', 8));
- }
- return sb.toString();
- }
Advertisement
Add Comment
Please, Sign In to add comment