Java Bit String From toBitString(final StringBuilder sb, final byte value, final int count2)

Here you can find the source of toBitString(final StringBuilder sb, final byte value, final int count2)

Description

to Bit String

License

Open Source License

Declaration

public static void toBitString(final StringBuilder sb, final byte value, final int count2) 

Method Source Code

//package com.java2s;
// and/or modify it under the terms of the GNU General Public License 

public class Main {
    public static void toBitString(final StringBuilder sb, final byte value, final int count2) {
        int count = count2;
        if (count > 8) {
            count = 8;/* w  ww  . j a  v  a 2 s .co m*/
        }
        char[] data = new char[count];
        for (int pos = 0; pos != count; ++pos) {
            if ((value & (1 << pos)) != 0) {
                data[count - pos - 1] = '1';
            } else {
                data[count - pos - 1] = '0';
            }
        }
        sb.append(data);
    }
}

Related

  1. toBitString(byte[] data)
  2. toBitString(final byte n)
  3. toBitString(final byte[] b)
  4. toBitString(final byte[] b)
  5. toBitString(final double d)
  6. toBitString(int i)
  7. toBitString(int meta)
  8. toBitString(long i)