Java Utililty Methods Number Swap

List of utility methods to do Number Swap

Description

The list of methods to do Number Swap are organized into topic(s).

Method

intswap16(final int aValue)
Switches the order of bytes of the given (16-bit) word value.
return (((aValue & 0x00ff) << 8) | ((aValue & 0xff00) >> 8));
shortswap16(short rgb)
swap
int a = (rgb >> 8) & 0xFF;
int r = rgb & 0xff;
return (short) ((r << 8) | a);
intswap32(int rgb)
swap
int a = (rgb >> 24) & 0xFF;
int r = (rgb >> 16) & 0xff;
int g = (rgb >> 8) & 0xff;
int b = rgb & 0xff;
return (b << 24) | (g << 16) | (r << 8) | a;
voidswapAddresses(T o1, T o2)
swap Addresses
T temp = o2;
o2 = o1;
o1 = temp;
byteswapBits(byte in)
swap Bits
return (byte) ((swapped_nybbles[in & 0xf] << 4) | (swapped_nybbles[(in & 0xf0) >> 4]));
intswapBits(int b, int i, int j)
swap Bits
final int x = ((b >> i) ^ (b >> j)) & 1; 
return b ^ ((x << i) | (x << j));
intswapByte(byte b)
swap Byte
int high = (0x0000000F & ((int) b));
high = high << 4;
int low = (int) b >> 4;
return high + low;
intswapBytes(final int i)
Swap bytes
return (i << 24) | ((i << 8) & 0x00ff0000) | (i >>> 24) | ((i >> 8) & 0x0000ff00);
StringswapCasing(String str)
swap Casing
int strLen;
if ((str == null) || ((strLen = str.length()) == 0)) {
    return str;
StringBuilder builder = new StringBuilder(strLen);
char ch = 0;
for (int i = 0; i < strLen; i++) {
    ch = str.charAt(i);
...
doubleswapDouble(double value)
Reverses the byte order of the source double value
long l = Double.doubleToLongBits(value);
l = swapLong(l);
return Double.longBitsToDouble(l);