Java Byte Array Print printByteArray(byte[] bytes)

Here you can find the source of printByteArray(byte[] bytes)

Description

print Byte Array

License

Apache License

Declaration

public static void printByteArray(byte[] bytes) 

Method Source Code

//package com.java2s;
/**//  w ww .  ja  v  a2s.co m
 * Copyright 2005 Refactored Networks, LLC
    
   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at
    
   http://www.apache.org/licenses/LICENSE-2.0
    
   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
    
 */

public class Main {
    public static void printByteArray(byte[] bytes) {
        System.out.println("----------------------------------");
        System.out.println("byte[] length is " + bytes.length * 8);
        for (int i = 0; i < bytes.length; i++) {
            if (((i - 1) % 8) == 0) {
                System.out.print(" ");
            }
            for (int j = 0; j < 8; j++) {
                if ((bytes[i] & (1 << j)) == 1) {
                    System.out.print("1");
                } else {
                    System.out.print("0");
                }
            }
        }
        System.out.println("\n--------------------------------");
    }
}

Related

  1. printByteArray(byte b[])
  2. printByteArray(byte[] bytes)
  3. printByteArray(byte[] bytes)
  4. printByteArray(byte[] bytes)
  5. printByteArray(byte[] bytes)
  6. printByteArray(byte[] input)
  7. printByteArrayAsChars(byte[] bytes)
  8. printByteArrayToHex(byte[] byteArray, int length)
  9. printByteHexEncoded(byte b)