Here you can find the source of toBinFromByte(final byte b)
Parameter | Description |
---|---|
b | The byte to convert |
public static String toBinFromByte(final byte b)
//package com.java2s; //License from project: Open Source License public class Main { /** Allowable binary values */ private final static String[] binSymbols = { "0", "1" }; /**/*from www. j av a2 s. c o m*/ * Transform a byte into a bitstring (of length 8) * * @param b * The byte to convert * @return The binary String representing the input byte */ public static String toBinFromByte(final byte b) { StringBuilder binBuffer = new StringBuilder(8); // We need to read each of the 8 bits out of the // input byte and append them one by one to the // output bit string binBuffer.append(binSymbols[((b & 0x80) >>> 7)]); binBuffer.append(binSymbols[((b & 0x40) >>> 6)]); binBuffer.append(binSymbols[((b & 0x20) >>> 5)]); binBuffer.append(binSymbols[((b & 0x10) >>> 4)]); binBuffer.append(binSymbols[((b & 0x08) >>> 3)]); binBuffer.append(binSymbols[((b & 0x04) >>> 2)]); binBuffer.append(binSymbols[((b & 0x02) >>> 1)]); binBuffer.append(binSymbols[(b & 0x01)]); return (binBuffer.toString()); } }