Java Utililty Methods Bit Flip

List of utility methods to do Bit Flip

Description

The list of methods to do Bit Flip are organized into topic(s).

Method

intflip(int i)
Flips the byte order of an integer
int result = 0;
result |= (i & 0xFF) << 24;
result |= (i & 0xFF00) << 8;
result |= ((i & 0xFF0000) >> 8) & 0xFF00;
result |= ((i & 0xFF000000) >> 24) & 0xFF;
return result;
intflip(int value)
flip
return value ^ Integer.MIN_VALUE;
longflip(long a)
A (self-inverse) bijection which converts the ordering on unsigned longs to the ordering on longs, that is, a <= b as unsigned longs if and only if flip(a) <= flip(b) as signed longs.
return a ^ Long.MIN_VALUE;
intflipBitAsBinaryString(int flipBit)
flip Bit As Binary String
return 1 << flipBit;
byteflipBitAt(int bitIndex, byte b)
bitIndex from right to left (0 = least significant = rightmost bit)
return (byte) ((int) b ^ (1 << (bitIndex & 31)));
voidflipBits(byte[] bytes, int start, int bitLength)
flip Bits
for (int i = 0; i < bitLength / 2; i++) {
    boolean leftBit = getBit(bytes, start * 8 + i);
    boolean rightBit = getBit(bytes, start * 8 + bitLength - i - 1);
    setBit(bytes, start * 8 + i, rightBit);
    setBit(bytes, start * 8 + bitLength - i - 1, leftBit);
intflipBits(int n)
flip Bits
System.out.println("n = " + Integer.toBinaryString(n));
int mask = 0;
for (int i = 0; i < 31; i++) {
    mask <<= 1;
    if (i % 2 == 0)
        mask |= 1;
System.out.println("mask = " + Integer.toBinaryString(mask));
...
intflipBits(int value)
flip Bits
return ~value;
longflipC(long v, int off)
Invert bit number "off" in v.
v ^= (1L << off);
return v;
intFLIPENDIAN_INT32(int x)
FLIPENDIAINT
return (x << 24) | (x >>> 24) | ((x & 0x0000ff00) << 8) | ((x & 0x00ff0000) >> 8);