@Test public void testReversing() { TestCase.assertEquals((byte)0b10000000, BitMagic.reverse((byte)0b00000001)); TestCase.assertEquals((byte)0b11000000, BitMagic.reverse((byte)0b00000011)); TestCase.assertEquals((byte)0b10001000, BitMagic.reverse((byte)0b00010001)); TestCase.assertEquals((byte)0x00, BitMagic.reverse((byte)0x00)); TestCase.assertEquals((byte)0xFF, BitMagic.reverse((byte)0xFF)); }
public static byte reverse(byte b) { b = (byte) ((b & 0xF0) >> 4 | (b & 0x0F) << 4); b = (byte) ((b & 0xCC) >> 2 | (b & 0x33) << 2); b = (byte) ((b & 0xAA) >> 1 | (b & 0x55) << 1); return b; }
BitMagic { public static byte reverse(byte b) { b = (byte) ((b & 0xF0) >> 4 | (b & 0x0F) << 4); b = (byte) ((b & 0xCC) >> 2 | (b & 0x33) << 2); b = (byte) ((b & 0xAA) >> 1 | (b & 0x55) << 1); return b; } }
BitMagic { public static byte reverse(byte b) { b = (byte) ((b & 0xF0) >> 4 | (b & 0x0F) << 4); b = (byte) ((b & 0xCC) >> 2 | (b & 0x33) << 2); b = (byte) ((b & 0xAA) >> 1 | (b & 0x55) << 1); return b; }  }
BitMagic { public static byte reverse(byte b) { b = (byte) ((b & 0xF0) >> 4 | (b & 0x0F) << 4); b = (byte) ((b & 0xCC) >> 2 | (b & 0x33) << 2); b = (byte) ((b & 0xAA) >> 1 | (b & 0x55) << 1); return b; }  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 byte reverse(byte b) { b = (byte) ((b & 0xF0) >> 4 | (b & 0x0F) << 4); b = (byte) ((b & 0xCC) >> 2 | (b & 0x33) << 2); b = (byte) ((b & 0xAA) >> 1 | (b & 0x55) << 1); return b; }  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);  }