Java Binary Encode toBinaryString(final char[] arr)

Here you can find the source of toBinaryString(final char[] arr)

Description

to Binary String

License

Open Source License

Declaration

public static String toBinaryString(final char[] arr) 

Method Source Code

//package com.java2s;

public class Main {
    public static String toBinaryString(final byte[] arr) {
        final StringBuilder buffer = new StringBuilder();
        buffer.append('[');
        if (arr.length > 0)
            buffer.append(Integer.toBinaryString(arr[0]));
        for (int i = 1; i < arr.length; i++) {
            buffer.append(' ');
            buffer.append(Integer.toBinaryString(arr[i]));
        }//w  w w  .  j a va2s .  c  o m
        buffer.append(']');
        return buffer.toString();
    }

    public static String toBinaryString(final char[] arr) {
        final StringBuilder buffer = new StringBuilder();
        buffer.append('[');
        if (arr.length > 0)
            buffer.append(Integer.toBinaryString(arr[0]));
        for (int i = 1; i < arr.length; i++) {
            buffer.append(' ');
            buffer.append(Integer.toBinaryString(arr[i]));
        }
        buffer.append(']');
        return buffer.toString();
    }

    public static String toBinaryString(final short[] arr) {
        final StringBuilder buffer = new StringBuilder();
        buffer.append('[');
        if (arr.length > 0)
            buffer.append(Integer.toBinaryString(arr[0]));
        for (int i = 1; i < arr.length; i++) {
            buffer.append(' ');
            buffer.append(Integer.toBinaryString(arr[i]));
        }
        buffer.append(']');
        return buffer.toString();
    }

    public static String toBinaryString(final int[] arr) {
        final StringBuilder buffer = new StringBuilder();
        buffer.append('[');
        if (arr.length > 0)
            buffer.append(Integer.toBinaryString(arr[0]));
        for (int i = 1; i < arr.length; i++) {
            buffer.append(' ');
            buffer.append(Integer.toBinaryString(arr[i]));
        }
        buffer.append(']');
        return buffer.toString();
    }

    public static String toBinaryString(final long[] arr) {
        final StringBuilder buffer = new StringBuilder();
        buffer.append('[');
        if (arr.length > 0)
            buffer.append(Long.toBinaryString(arr[0]));
        for (int i = 1; i < arr.length; i++) {
            buffer.append(' ');
            buffer.append(Long.toBinaryString(arr[i]));
        }
        buffer.append(']');
        return buffer.toString();
    }
}

Related

  1. toBinaryString(byte[] bytes, int bitSize)
  2. toBinaryString(byte[] data, boolean format)
  3. toBinaryString(char value)
  4. toBinaryString(final boolean[] bits)
  5. toBinaryString(final byte number)
  6. toBinaryString(int a, int bits)
  7. toBinaryString(int b, int bits)
  8. toBinaryString(int l, int L)
  9. toBinaryString(int number)