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

intswap(final int value)
Performs a byte-order swap for a 32-bit signed integer.
return (((value << 24) & 0xFF000000) | ((value << 8) & 0x00FF0000) | ((value >> 8) & 0x0000FF00)
        | ((value >> 24) & 0x000000FF));
longswap(int elementWidth, long value)
swap
return Long.reverseBytes(value) >>> (8 * (8 - elementWidth));
voidswap(Integer i, Integer j)
swap
System.out.println("i=" + i + ", j=" + j);
if (i != j) {
    i ^= j;
    j ^= i;
    i ^= j;
System.out.println("i=" + i + ", j=" + j);
shortswap(short myShort)
Swaps byte order, short.
return (short) (((myShort & 0xff00) >> 8) | ((myShort & 0x00ff) << 8));
shortswap(short value)
Swap the bytes in the value, thereby converting a big-endian value into a little-endian value (or vice versa).
return (short) ((0x00ff & (value >>> 8)) | (0xff00 & (value << 8)));
shortswap(short x)
swap
return (short) ((x << 8) | ((char) x >>> 8));
Stringswap(String str, int i, int j)
swap
char[] chars = str.toCharArray();
char temp = chars[i];
chars[i] = chars[j];
chars[j] = temp;
return String.valueOf(chars);
voidswap(StringBuffer s, int i, int j)
Swap s.charAt(i) and s.charAt(j).
final char c = s.charAt(i);
s.setCharAt(i, s.charAt(j));
s.setCharAt(j, c);
voidswap(T a, T b)
swap
T temp = a;
a = b;
b = temp;
Tswap(T... args)
swap
return args[0];