Java Byte to Bit byteToBits(byte b)

Here you can find the source of byteToBits(byte b)

Description

byte To Bits

License

Open Source License

Declaration

public static final String byteToBits(byte b) 

Method Source Code

//package com.java2s;
/**/*from   w  ww  .j a  v  a 2  s .c  o  m*/
  *         Commmon Internet File System Java API (JCIFS)
  *----------------------------------------------------------------
  *  Copyright (C) 1999  Norbert Hranitzky
  *
  *  This program is free software; you can redistribute it and/or
  *  modify it under the terms of the GNU General Public License as
  *  published by the Free Software Foundation; either version 2 of
  *  the License, or (at your option) any later version.
  *
  *  This program is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  *  General Public License for more details.
  *
  *  You should have received a copy of the GNU General Public License
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
  *  The full copyright text: http://www.gnu.org/copyleft/gpl.html
  *
  *----------------------------------------------------------------
  *  Author: Norbert Hranitzky
  *  Email : norbert.hranitzky@mchp.siemens.de
  *  Web   : http://www.hranitzky.purespace.de
  */

public class Main {
    public static final String byteToBits(byte b) {
        StringBuffer buf = new StringBuffer();

        int n = 256;
        for (int i = 0; i < 8; i++) {
            n /= 2;
            if ((b & n) != 0)
                buf.append('1');
            else
                buf.append('0');
        }
        return buf.toString();
    }
}

Related

  1. byteToBitArray(byte b)
  2. byteToBits(byte b)
  3. byteToBits(byte b)
  4. byteToBits(byte b)
  5. byteToBits(byte b)
  6. byteToBitsArray(byte b)
  7. byteToBitStr(byte b)