@Test public void testBitToString() { TestCase.assertEquals("0b00000000", BitMagic.toBitString((byte)0b00000000)); TestCase.assertEquals("0b00100010", BitMagic.toBitString((byte)0b00100010)); TestCase.assertEquals("0b11111111", BitMagic.toBitString((byte)0b11111111)); TestCase.assertEquals("0b0000000000000000", BitMagic.toBitString((short)0b00000000)); TestCase.assertEquals("0b0000000000100010", BitMagic.toBitString((short)0b00100010)); TestCase.assertEquals("0b0000000011111111", BitMagic.toBitString((short)0b11111111)); TestCase.assertEquals("0b00000000000000000000000000000000", BitMagic.toBitString(0b00000000)); TestCase.assertEquals("0b00000000000000000000000000100010", BitMagic.toBitString(0b00100010)); TestCase.assertEquals("0b00000000000000000000000011111111", BitMagic.toBitString(0b11111111)); TestCase.assertEquals("0b0000000000000000000000000000000000000000000000000000000000000000", BitMagic.toBitString(0b00000000L)); TestCase.assertEquals("0b0000000000000000000000000000000000000000000000000000000000100010", BitMagic.toBitString(0b00100010L)); TestCase.assertEquals("0b0000000000000000000000000000000000000000000000000000000011111111", BitMagic.toBitString(0b11111111L)); }
public static String toBitString(byte b) { String s = String.format("0b%8s", Integer.toBinaryString(b & 0xFF)).replace(' ', '0'); return s; }
BitMagic { public static String toBitString(byte b) { String s = String.format("0b%8s", Integer.toBinaryString(b & 0xFF)).replace(' ', '0'); return s; } }
BitMagic { public static String toBitString(byte b) { String s = String.format("0b%8s", Integer.toBinaryString(b & 0xFF)).replace(' ', '0'); return s; }  }
BitMagic { public static String toBitString(byte b) { String s = String.format("0b%8s", Integer.toBinaryString(b & 0xFF)).replace(' ', '0'); return s; }  static int getBit(byte b, int bitPosition); static int getBit(short word, int bitPosition); static int getBit(int dword, int bitPosition); static int getBit(long qword, int bitPosition); static byte setBit(byte b, int bitPosition, int value); static short setBit(short word, int bitPosition, int value); static int setBit(int dword, int bitPosition, int value); static long setBit(long qword, int bitPosition, int value); static boolean isBitSet(byte b, int bitPosition); static boolean isBitSet(short word, int bitPosition); static boolean isBitSet(int dword, int bitPosition); static boolean isBitSet(long qword, int bitPosition); static byte toggleBit(byte b, int bitPosition); static short toggleBit(short word, int bitPosition); static int toggleBit(int dword, int bitPosition); static long toggleBit(long qword, int bitPosition); static String toBitString(byte b); static String toBitString(short word); static String toBitString(int dword); static String toBitString(long qword); static byte getLowerNibble(byte b); static byte getUpperNibble(byte b); static byte byteFromNibbles(int upperNibble, int lowerNibble); static byte byteFromNibbles(byte upperNibble, byte lowerNibble); static byte reverse(byte b); }
BitMagic { public static String toBitString(byte b) { String s = String.format("0b%8s", Integer.toBinaryString(b & 0xFF)).replace(' ', '0'); return s; }  static int getBit(byte b, int bitPosition); static int getBit(short word, int bitPosition); static int getBit(int dword, int bitPosition); static int getBit(long qword, int bitPosition); static byte setBit(byte b, int bitPosition, int value); static short setBit(short word, int bitPosition, int value); static int setBit(int dword, int bitPosition, int value); static long setBit(long qword, int bitPosition, int value); static boolean isBitSet(byte b, int bitPosition); static boolean isBitSet(short word, int bitPosition); static boolean isBitSet(int dword, int bitPosition); static boolean isBitSet(long qword, int bitPosition); static byte toggleBit(byte b, int bitPosition); static short toggleBit(short word, int bitPosition); static int toggleBit(int dword, int bitPosition); static long toggleBit(long qword, int bitPosition); static String toBitString(byte b); static String toBitString(short word); static String toBitString(int dword); static String toBitString(long qword); static byte getLowerNibble(byte b); static byte getUpperNibble(byte b); static byte byteFromNibbles(int upperNibble, int lowerNibble); static byte byteFromNibbles(byte upperNibble, byte lowerNibble); static byte reverse(byte b);  }