java.lang.Object
org.bouncycastle.util.Pack
Utility methods for converting byte arrays into ints and longs, and back again.
Constructor Summary
ConstructorsConstructorDescriptionPack()Constructor for subclasses; the packing helpers in this base class are static.Method Summary
All MethodsModifier and TypeMethodDescriptionstatic intbigEndianToInt(byte[] bs, int off) Convert a big-endian byte array to an int.static voidbigEndianToInt(byte[] bs, int off, int[] ns) Convert a big-endian byte array to an array of ints.static voidbigEndianToInt(byte[] bs, int off, int[] ns, int nsOff, int nsLen) Convert a big-endian byte array to a range of an int array.static longbigEndianToLong(byte[] bs, int off) Convert a big-endian byte array to a long.static longbigEndianToLong(byte[] bs, int off, int len) Convert a big-endian byte array of variable length to a long.static voidbigEndianToLong(byte[] bs, int off, long[] ns) Convert a big-endian byte array to a long array.static voidbigEndianToLong(byte[] bs, int bsOff, long[] ns, int nsOff, int nsLen) Convert a big-endian byte array to a range of a long array.static shortbigEndianToShort(byte[] bs, int off) Convert a big-endian byte array to a short.static byte[]intToBigEndian(int n) Convert an int to a big-endian byte array.static byte[]intToBigEndian(int[] ns) Convert an int array to a big-endian byte array.static voidintToBigEndian(int[] ns, byte[] bs, int off) Write an int array to a byte array in big-endian order.static voidintToBigEndian(int[] ns, int nsOff, int nsLen, byte[] bs, int bsOff) Write a range of an int array to a byte array in big-endian order.static voidintToBigEndian(int n, byte[] bs, int off) Write an int to a byte array in big-endian order.static byte[]intToLittleEndian(int n) Convert an int to a little-endian byte array.static byte[]intToLittleEndian(int[] ns) Convert an int array to a little-endian byte array.static voidintToLittleEndian(int[] ns, byte[] bs, int off) Write an int array to a byte array in little-endian order.static voidintToLittleEndian(int[] ns, int nsOff, int nsLen, byte[] bs, int bsOff) Write a range of an int array to a byte array in little-endian order.static voidintToLittleEndian(int n, byte[] bs, int off) Write an int to a byte array in little-endian order.static intlittleEndianToInt(byte[] bs, int off) Convert a little-endian byte array to an int.static int[]littleEndianToInt(byte[] bs, int off, int count) Convert a little-endian byte array to a new int array of specified count.static voidlittleEndianToInt(byte[] bs, int off, int[] ns) Convert a little-endian byte array to an int array.static voidlittleEndianToInt(byte[] bs, int bOff, int[] ns, int nOff, int count) Convert a little-endian byte array to a range of an int array.static intlittleEndianToInt_High(byte[] bs, int off, int len) Convert a little-endian byte array of variable length to the high-order bits of an int.static intlittleEndianToInt_Low(byte[] bs, int off, int len) Convert a little-endian byte array of variable length to an int (low-order bits).static longlittleEndianToLong(byte[] bs, int off) Convert a little-endian byte array to a long.static longlittleEndianToLong(byte[] input, int off, int len) Convert a little-endian byte array of variable length to a long.static voidlittleEndianToLong(byte[] bs, int off, long[] ns) Convert a little-endian byte array to a long array.static voidlittleEndianToLong(byte[] bs, int bsOff, long[] ns, int nsOff, int nsLen) Convert a little-endian byte array to a range of a long array.static longlittleEndianToLong_High(byte[] bs, int off, int len) Convert a little-endian byte array of variable length to the high-order bits of a long.static longlittleEndianToLong_Low(byte[] bs, int off, int len) Convert a little-endian byte array of variable length to a long (low-order bits).static shortlittleEndianToShort(byte[] bs, int off) Convert a little-endian byte array to a short.static byte[]longToBigEndian(long n) Convert a long to a big-endian byte array.static byte[]longToBigEndian(long[] ns) Convert a long array to a big-endian byte array.static voidlongToBigEndian(long[] ns, byte[] bs, int off) Write a long array to a byte array in big-endian order.static voidlongToBigEndian(long[] ns, int nsOff, int nsLen, byte[] bs, int bsOff) Write a range of a long array to a byte array in big-endian order.static voidlongToBigEndian(long n, byte[] bs, int off) Write a long to a byte array in big-endian order.static byte[]longToLittleEndian(long n) Convert a long to a little-endian byte array.static byte[]longToLittleEndian(long[] ns) Convert a long array to a little-endian byte array.static voidlongToLittleEndian(long[] ns, byte[] bs, int off) Write a long array to a byte array in little-endian order.static voidlongToLittleEndian(long[] ns, int nsOff, int nsLen, byte[] bs, int bsOff) Write a range of a long array to a byte array in little-endian order.static voidlongToLittleEndian(long n, byte[] bs, int off) Write a long to a byte array in little-endian order.static voidlongToLittleEndian(long n, byte[] bs, int off, int len) Write a long to a byte array in little-endian order with variable length.static voidlongToLittleEndian_High(long n, byte[] bs, int off, int len) Write the high-order bytes of a long to a byte array in little-endian order.static byte[]shortToBigEndian(short n) Convert a short to a big-endian byte array.static voidshortToBigEndian(short n, byte[] bs, int off) Write a short to a byte array in big-endian order.static byte[]shortToLittleEndian(short n) Convert a short to a little-endian byte array.static voidshortToLittleEndian(short n, byte[] bs, int off) Write a short to a byte array in little-endian order.
Constructor Details
Pack
public Pack()Constructor for subclasses; the packing helpers in this base class are static.
Method Details
bigEndianToShort
public static short bigEndianToShort(byte[] bs, int off) Convert a big-endian byte array to a short.- Parameters:
bs- the byte arrayoff- the offset into the array- Returns:
- the short value
bigEndianToInt
public static int bigEndianToInt(byte[] bs, int off) Convert a big-endian byte array to an int.- Parameters:
bs- the byte arrayoff- the offset into the array- Returns:
- the int value
bigEndianToInt
public static void bigEndianToInt(byte[] bs, int off, int[] ns) Convert a big-endian byte array to an array of ints.- Parameters:
bs- the byte arrayoff- the offset into the arrayns- the output int array
bigEndianToInt
public static void bigEndianToInt(byte[] bs, int off, int[] ns, int nsOff, int nsLen) Convert a big-endian byte array to a range of an int array.- Parameters:
bs- the byte arrayoff- the offset into the arrayns- the output int arraynsOff- the offset into the output arraynsLen- the number of ints to write
intToBigEndian
public static byte[] intToBigEndian(int n) Convert an int to a big-endian byte array.- Parameters:
n- the int value- Returns:
- the byte array
intToBigEndian
public static void intToBigEndian(int n, byte[] bs, int off) Write an int to a byte array in big-endian order.- Parameters:
n- the int valuebs- the target byte arrayoff- the offset into the array
intToBigEndian
public static byte[] intToBigEndian(int[] ns) Convert an int array to a big-endian byte array.- Parameters:
ns- the int array- Returns:
- the byte array
intToBigEndian
public static void intToBigEndian(int[] ns, byte[] bs, int off) Write an int array to a byte array in big-endian order.- Parameters:
ns- the int arraybs- the target byte arrayoff- the offset into the array
intToBigEndian
public static void intToBigEndian(int[] ns, int nsOff, int nsLen, byte[] bs, int bsOff) Write a range of an int array to a byte array in big-endian order.- Parameters:
ns- the int arraynsOff- the offset into the int arraynsLen- the number of ints to writebs- the target byte arraybsOff- the offset into the byte array
bigEndianToLong
public static long bigEndianToLong(byte[] bs, int off) Convert a big-endian byte array to a long.- Parameters:
bs- the byte arrayoff- the offset into the array- Returns:
- the long value
bigEndianToLong
public static void bigEndianToLong(byte[] bs, int off, long[] ns) Convert a big-endian byte array to a long array.- Parameters:
bs- the byte arrayoff- the offset into the arrayns- the output long array
bigEndianToLong
public static void bigEndianToLong(byte[] bs, int bsOff, long[] ns, int nsOff, int nsLen) Convert a big-endian byte array to a range of a long array.- Parameters:
bs- the byte arraybsOff- the offset into the byte arrayns- the output long arraynsOff- the offset into the output arraynsLen- the number of longs to write
bigEndianToLong
public static long bigEndianToLong(byte[] bs, int off, int len) Convert a big-endian byte array of variable length to a long.- Parameters:
bs- the byte arrayoff- the offset into the arraylen- the number of bytes to read (1-8)- Returns:
- the long value
longToBigEndian
public static byte[] longToBigEndian(long n) Convert a long to a big-endian byte array.- Parameters:
n- the long value- Returns:
- the byte array
longToBigEndian
public static void longToBigEndian(long n, byte[] bs, int off) Write a long to a byte array in big-endian order.- Parameters:
n- the long valuebs- the target byte arrayoff- the offset into the array
longToBigEndian
public static byte[] longToBigEndian(long[] ns) Convert a long array to a big-endian byte array.- Parameters:
ns- the long array- Returns:
- the byte array
longToBigEndian
public static void longToBigEndian(long[] ns, byte[] bs, int off) Write a long array to a byte array in big-endian order.- Parameters:
ns- the long arraybs- the target byte arrayoff- the offset into the array
longToBigEndian
public static void longToBigEndian(long[] ns, int nsOff, int nsLen, byte[] bs, int bsOff) Write a range of a long array to a byte array in big-endian order.- Parameters:
ns- the long arraynsOff- the offset into the long arraynsLen- the number of longs to writebs- the target byte arraybsOff- the offset into the byte array
littleEndianToShort
public static short littleEndianToShort(byte[] bs, int off) Convert a little-endian byte array to a short.- Parameters:
bs- the byte arrayoff- the offset into the array- Returns:
- the short value
littleEndianToInt
public static int littleEndianToInt(byte[] bs, int off) Convert a little-endian byte array to an int.- Parameters:
bs- the byte arrayoff- the offset into the array- Returns:
- the int value
littleEndianToInt_High
public static int littleEndianToInt_High(byte[] bs, int off, int len) Convert a little-endian byte array of variable length to the high-order bits of an int.- Parameters:
bs- the byte arrayoff- the offset into the arraylen- the number of bytes to read (1-4)- Returns:
- the int value shifted into the high-order bits
littleEndianToInt_Low
public static int littleEndianToInt_Low(byte[] bs, int off, int len) Convert a little-endian byte array of variable length to an int (low-order bits).- Parameters:
bs- the byte arrayoff- the offset into the arraylen- the number of bytes to read (1-4)- Returns:
- the int value
littleEndianToInt
public static void littleEndianToInt(byte[] bs, int off, int[] ns) Convert a little-endian byte array to an int array.- Parameters:
bs- the byte arrayoff- the offset into the arrayns- the output int array
littleEndianToInt
public static void littleEndianToInt(byte[] bs, int bOff, int[] ns, int nOff, int count) Convert a little-endian byte array to a range of an int array.- Parameters:
bs- the byte arraybOff- the offset into the byte arrayns- the output int arraynOff- the offset into the output arraycount- the number of ints to write
littleEndianToInt
public static int[] littleEndianToInt(byte[] bs, int off, int count) Convert a little-endian byte array to a new int array of specified count.- Parameters:
bs- the byte arrayoff- the offset into the arraycount- the number of ints to read- Returns:
- the int array
shortToLittleEndian
public static byte[] shortToLittleEndian(short n) Convert a short to a little-endian byte array.- Parameters:
n- the short value- Returns:
- the byte array
shortToLittleEndian
public static void shortToLittleEndian(short n, byte[] bs, int off) Write a short to a byte array in little-endian order.- Parameters:
n- the short valuebs- the target byte arrayoff- the offset into the array
shortToBigEndian
public static byte[] shortToBigEndian(short n) Convert a short to a big-endian byte array.- Parameters:
n- the short value- Returns:
- the byte array
shortToBigEndian
public static void shortToBigEndian(short n, byte[] bs, int off) Write a short to a byte array in big-endian order.- Parameters:
n- the short valuebs- the target byte arrayoff- the offset into the array
intToLittleEndian
public static byte[] intToLittleEndian(int n) Convert an int to a little-endian byte array.- Parameters:
n- the int value- Returns:
- the byte array
intToLittleEndian
public static void intToLittleEndian(int n, byte[] bs, int off) Write an int to a byte array in little-endian order.- Parameters:
n- the int valuebs- the target byte arrayoff- the offset into the array
intToLittleEndian
public static byte[] intToLittleEndian(int[] ns) Convert an int array to a little-endian byte array.- Parameters:
ns- the int array- Returns:
- the byte array
intToLittleEndian
public static void intToLittleEndian(int[] ns, byte[] bs, int off) Write an int array to a byte array in little-endian order.- Parameters:
ns- the int arraybs- the target byte arrayoff- the offset into the array
intToLittleEndian
public static void intToLittleEndian(int[] ns, int nsOff, int nsLen, byte[] bs, int bsOff) Write a range of an int array to a byte array in little-endian order.- Parameters:
ns- the int arraynsOff- the offset into the int arraynsLen- the number of ints to writebs- the target byte arraybsOff- the offset into the byte array
littleEndianToLong
public static long littleEndianToLong(byte[] bs, int off) Convert a little-endian byte array to a long.- Parameters:
bs- the byte arrayoff- the offset into the array- Returns:
- the long value
littleEndianToLong
public static void littleEndianToLong(byte[] bs, int off, long[] ns) Convert a little-endian byte array to a long array.- Parameters:
bs- the byte arrayoff- the offset into the arrayns- the output long array
littleEndianToLong
public static long littleEndianToLong(byte[] input, int off, int len) Convert a little-endian byte array of variable length to a long.- Parameters:
input- the byte arrayoff- the offset into the arraylen- the number of bytes to read (1-8)- Returns:
- the long value
littleEndianToLong
public static void littleEndianToLong(byte[] bs, int bsOff, long[] ns, int nsOff, int nsLen) Convert a little-endian byte array to a range of a long array.- Parameters:
bs- the byte arraybsOff- the offset into the byte arrayns- the output long arraynsOff- the offset into the output arraynsLen- the number of longs to write
longToLittleEndian_High
public static void longToLittleEndian_High(long n, byte[] bs, int off, int len) Write the high-order bytes of a long to a byte array in little-endian order.- Parameters:
n- the long valuebs- the target byte arrayoff- the offset into the arraylen- the number of bytes to write (1-8)
longToLittleEndian
public static void longToLittleEndian(long n, byte[] bs, int off, int len) Write a long to a byte array in little-endian order with variable length.- Parameters:
n- the long valuebs- the target byte arrayoff- the offset into the arraylen- the number of bytes to write (1-8)
littleEndianToLong_High
public static long littleEndianToLong_High(byte[] bs, int off, int len) Convert a little-endian byte array of variable length to the high-order bits of a long.- Parameters:
bs- the byte arrayoff- the offset into the arraylen- the number of bytes to read (1-8)- Returns:
- the long value shifted into the high-order bits
littleEndianToLong_Low
public static long littleEndianToLong_Low(byte[] bs, int off, int len) Convert a little-endian byte array of variable length to a long (low-order bits).- Parameters:
bs- the byte arrayoff- the offset into the arraylen- the number of bytes to read (1-8)- Returns:
- the long value
longToLittleEndian
public static byte[] longToLittleEndian(long n) Convert a long to a little-endian byte array.- Parameters:
n- the long value- Returns:
- the byte array
longToLittleEndian
public static void longToLittleEndian(long n, byte[] bs, int off) Write a long to a byte array in little-endian order.- Parameters:
n- the long valuebs- the target byte arrayoff- the offset into the array
longToLittleEndian
public static byte[] longToLittleEndian(long[] ns) Convert a long array to a little-endian byte array.- Parameters:
ns- the long array- Returns:
- the byte array
longToLittleEndian
public static void longToLittleEndian(long[] ns, byte[] bs, int off) Write a long array to a byte array in little-endian order.- Parameters:
ns- the long arraybs- the target byte arrayoff- the offset into the array
longToLittleEndian
public static void longToLittleEndian(long[] ns, int nsOff, int nsLen, byte[] bs, int bsOff) Write a range of a long array to a byte array in little-endian order.- Parameters:
ns- the long arraynsOff- the offset into the long arraynsLen- the number of longs to writebs- the target byte arraybsOff- the offset into the byte array