List of utility methods to do Number Swap
double | swapDouble(double value) Converts a "double" value between endian systems. return Double.longBitsToDouble(swapLong(Double.doubleToLongBits(value)));
|
float | swapFloat(float floatValue) Byte-swaps the given float to the other endian. return Float.intBitsToFloat(swapInteger(Float.floatToRawIntBits(floatValue)));
|
float | swapFloat(float value) Reverses the byte order of the source float value int i = Float.floatToIntBits(value); i = swapInteger(i); return Float.intBitsToFloat(i); |
int | swapInt(int i) Converts an "int" value between endian systems. return ((i & 0xFF) << 24) | ((i & 0xFF00) << 8) | ((i & 0xFF0000) >> 8) | ((i >> 24) & 0xFF);
|
int | swapInt(int i) swap Int int a = i % 256; int b = i / 256; return a * 256 + b; |
int | swapInteger(int integer) Byte-swaps the given integer to the other endian. int swapped = 0, byte1, byte2, byte3, byte4; byte1 = (integer >> 0) & 0xff; byte2 = (integer >> 8) & 0xff; byte3 = (integer >> 16) & 0xff; byte4 = (integer >> 24) & 0xff; swapped = byte1 << 24 | byte2 << 16 | byte3 << 8 | byte4 << 0; return swapped; |
long | swapLong(long value) Reverses the byte order of the source long value return ((value & 0xFF00000000000000L) >> 56) | ((value & 0x00FF000000000000L) >> 40)
| ((value & 0x0000FF0000000000L) >> 24) | ((value & 0x000000FF00000000L) >> 8)
| ((value & 0x00000000FF000000L) << 8) | ((value & 0x0000000000FF0000L) << 24)
| ((value & 0x000000000000FF00L) << 40) | ((value & 0x00000000000000FFL) << 56);
|
long | swapLong(long value) Converts a "long" value between endian systems. return (((value >> 0) & 0xff) << 56) | (((value >> 8) & 0xff) << 48) | (((value >> 16) & 0xff) << 40)
| (((value >> 24) & 0xff) << 32) | (((value >> 32) & 0xff) << 24) | (((value >> 40) & 0xff) << 16)
| (((value >> 48) & 0xff) << 8) | (((value >> 56) & 0xff) << 0);
|
long | swapLong(long value) Converts a "long" value between endian systems. return (((value >> 0) & 0xff) << 56) + (((value >> 8) & 0xff) << 48) + (((value >> 16) & 0xff) << 40)
+ (((value >> 24) & 0xff) << 32) + (((value >> 32) & 0xff) << 24) + (((value >> 40) & 0xff) << 16)
+ (((value >> 48) & 0xff) << 8) + (((value >> 56) & 0xff) << 0);
|
short | swapShort(final short value) Converts a "short" value between endian systems. final int result = (((value >> 0) & INT_LOW_BYTE_MASK) << BIT_SIZE_OF_BYTE) + (((value >> BIT_SIZE_OF_BYTE) & INT_LOW_BYTE_MASK) << 0); return (short) result; |