public class Swap
extends java.lang.Object
Constructor and Description |
---|
Swap() |
Modifier and Type | Method and Description |
---|---|
static byte[] |
intToBytes(int v)
Convert an int to an array of 4 bytes.
|
static byte[] |
longToBytes(long v)
Convert a long to an array of 8 bytes.
|
static byte[] |
shortToBytes(short v)
Convert a short to an array of 2 bytes.
|
static char |
swapChar(byte[] b,
int offset)
Returns the char resulting from swapping 2 bytes at a specified
offset in a byte array.
|
static double |
swapDouble(byte[] b,
int offset)
Returns the double resulting from reversing 8 bytes at a specified
offset in a byte array.
|
static double |
swapDouble(double v)
Returns the double resulting from reversing 8 bytes of a specified
double.
|
static float |
swapFloat(byte[] b,
int offset)
Returns the float resulting from reversing 4 bytes at a specified
offset in a byte array.
|
static float |
swapFloat(float v)
Returns the float resulting from reversing 4 bytes of a specified
float.
|
static int |
swapInt(byte[] b,
int offset)
Returns the int resulting from reversing 4 bytes at a specified
offset in a byte array.
|
static int |
swapInt(int v)
Returns the int resulting from reversing 4 bytes of a specified
int.
|
static long |
swapLong(byte[] b,
int offset)
Returns the long resulting from reversing 8 bytes at a specified
offset in a byte array.
|
static long |
swapLong(long l)
Returns the long resulting from reversing 8 bytes of a specified
long.
|
static short |
swapShort(byte[] b,
int offset)
Returns the short resulting from swapping 2 bytes at a specified
offset in a byte array.
|
static short |
swapShort(short s)
Returns the short resulting from swapping 2 bytes of a specified
short.
|
public static short swapShort(byte[] b, int offset)
b
- the byte arrayoffset
- the offset of the first byteb[offset+1], b[offset]
public static int swapInt(byte[] b, int offset)
b
- the byte arrayoffset
- the offset of the first byteb[offset+3], b[offset+2], ..., b[offset]
public static long swapLong(byte[] b, int offset)
b
- the byte arrayoffset
- the offset of the first byteb[offset+7], b[offset+6], ..., b[offset]
public static float swapFloat(byte[] b, int offset)
b
- the byte arrayoffset
- the offset of the first byteb[offset+3], b[offset+2], ..., b[offset]
public static double swapDouble(byte[] b, int offset)
b
- the byte arrayoffset
- the offset of the first byteb[offset+7], b[offset+6], ..., b[offset]
public static char swapChar(byte[] b, int offset)
b
- the byte arrayoffset
- the offset of the first byteb[offset+1], b[offset]
public static short swapShort(short s)
s
- input value for which byte reversal is desireds
reversedpublic static int swapInt(int v)
v
- input value for which byte reversal is desiredv
reversedpublic static long swapLong(long l)
l
- input value for which byte reversal is desiredl
reversedpublic static float swapFloat(float v)
v
- input value for which byte reversal is desiredv
reversedpublic static double swapDouble(double v)
v
- input value for which byte reversal is desiredv
reversedpublic static byte[] shortToBytes(short v)
v
- input valuepublic static byte[] intToBytes(int v)
v
- input valuepublic static byte[] longToBytes(long v)
v
- input value