public final class Integers
extends java.lang.Object
| 构造器和说明 |
|---|
Integers() |
| 限定符和类型 | 方法和说明 |
|---|---|
static int |
bitLen(long val)
NOTE: will always return
Long.SIZE for negative integers. |
static java.math.BigInteger |
getBigInt(byte[] bytes,
int i,
int len) |
static byte |
getByte(byte[] buffer,
int i,
int len)
Retrieves an integer up to one byte in length.
|
static int |
getInt(byte[] buffer,
int i,
int len)
Retrieves an integer up to four bytes in length.
|
static long |
getLong(byte[] buffer,
int i,
int len)
Retrieves an integer up to eight bytes in length.
|
static short |
getShort(byte[] buffer,
int i,
int len)
Retrieves an integer up to two bytes in length.
|
static int |
insertBytes(int n,
byte[] b,
int i,
byte w,
byte x,
byte y,
byte z) |
static int |
insertBytes(int n,
byte[] b,
int i,
byte s,
byte t,
byte u,
byte v,
byte w,
byte x,
byte y,
byte z)
Inserts bytes into an array in the order they are given.
|
static int |
insertBytes(int n,
java.nio.ByteBuffer b,
byte s,
byte t,
byte u,
byte v,
byte w,
byte x,
byte y,
byte z) |
static int |
len(byte val)
Returns the byte length of an integer's minimal (without leading zeroes) two's complement representation.
|
static int |
len(int val)
Returns the byte length of an integer's minimal (without leading zeroes) two's complement representation.
|
static int |
len(long val)
Returns the byte length of an integer's minimal (without leading zeroes) two's complement representation.
|
static int |
len(short val)
Returns the byte length of an integer's minimal (without leading zeroes) two's complement representation.
|
static int |
putBigInt(java.math.BigInteger val,
byte[] o,
int i) |
static int |
putByte(byte val,
byte[] o,
int i)
Inserts into a byte array an integer's minimal (without leading zeroes), big-endian two's complement representation,
up to one byte in length.
|
static int |
putInt(int val,
byte[] o,
int i)
Inserts into a byte array an integer's minimal (without leading zeroes), big-endian two's complement representation,
up to four bytes in length.
|
static int |
putLong(long val,
byte[] o,
int i)
Inserts into a byte array an integer's minimal (without leading zeroes), big-endian two's complement representation,
up to eight bytes in length.
|
static int |
putLong(long val,
java.nio.ByteBuffer o) |
static int |
putShort(short val,
byte[] o,
int i)
Inserts into a byte array an integer's minimal (without leading zeroes), big-endian two's complement representation,
up to two bytes in length.
|
static byte[] |
toBytes(byte val)
Returns an integer's minimal big-endian two's complement representation.
|
static byte[] |
toBytes(int val)
Returns an integer's minimal big-endian two's complement representation.
|
static byte[] |
toBytes(long val)
Returns an integer's minimal big-endian two's complement representation.
|
static byte[] |
toBytes(short val)
Returns an integer's minimal big-endian two's complement representation.
|
public static byte[] toBytes(byte val)
val - the integerpublic static byte[] toBytes(short val)
val - the integerpublic static byte[] toBytes(int val)
val - the integerpublic static byte[] toBytes(long val)
val - the integerpublic static int putByte(byte val,
byte[] o,
int i)
val - the integer to be insertedo - the output arrayi - the index into the outputtoBytes(byte),
getByte(byte[], int, int)public static int putShort(short val,
byte[] o,
int i)
val - the integer to be insertedo - the output arrayi - the index into the outputtoBytes(short),
getShort(byte[], int, int)public static int putInt(int val,
byte[] o,
int i)
val - the integer to be insertedo - the output arrayi - the index into the outputtoBytes(int),
getInt(byte[], int, int)public static int putLong(long val,
byte[] o,
int i)
val - the integer to be insertedo - the output arrayi - the index into the outputtoBytes(long),
getLong(byte[], int, int)public static int putLong(long val,
java.nio.ByteBuffer o)
public static byte getByte(byte[] buffer,
int i,
int len)
throws DecodeException
buffer - the array containing the integeri - the array index locating the integerlen - the length in bytes of the integer's representationDecodeException - if the integer's representation is found to have leading zeroestoBytes(byte),
putByte(byte, byte[], int)public static short getShort(byte[] buffer,
int i,
int len)
throws DecodeException
buffer - the array containing the integer's representationi - the array index locating the integerlen - the length in bytes of the integer's representation, without leading zeroesDecodeException - if the integer's representation is found to have leading zeroestoBytes(short),
putShort(short, byte[], int)public static int getInt(byte[] buffer,
int i,
int len)
throws DecodeException
buffer - the array containing the integer's representationi - the array index locating the integerlen - the length in bytes of the integer's representation, without leading zeroesDecodeException - if the integer's representation is found to have leading zeroestoBytes(int),
putInt(int, byte[], int)public static long getLong(byte[] buffer,
int i,
int len)
throws DecodeException
buffer - the array containing the integer's representationi - the array index locating the integerlen - the length in bytes of the integer's representation, without leading zeroesDecodeException - if the integer's representation is found to have leading zeroestoBytes(long),
putLong(long, byte[], int)public static int len(byte val)
val - the integerpublic static int len(short val)
val - the integerpublic static int len(int val)
val - the integerpublic static int len(long val)
val - the integerpublic static int bitLen(long val)
Long.SIZE for negative integers. See also BizarroIntegers.bitLen(long).val - the long valuepublic static int insertBytes(int n,
byte[] b,
int i,
byte w,
byte x,
byte y,
byte z)
public static int insertBytes(int n,
byte[] b,
int i,
byte s,
byte t,
byte u,
byte v,
byte w,
byte x,
byte y,
byte z)
n - the number of bytes to insertb - the buffer into which the bytes will be insertedi - the index at which to inserts - the lead byte if eight bytes are to be insertedt - the lead byte if seven bytes are to be insertedu - the lead byte if six bytes are to be insertedv - the lead byte if five bytes are to be insertedw - the lead byte if four bytes are to be insertedx - the lead byte if three bytes are to be insertedy - the lead byte if two bytes are to be insertedz - the last bytepublic static int insertBytes(int n,
java.nio.ByteBuffer b,
byte s,
byte t,
byte u,
byte v,
byte w,
byte x,
byte y,
byte z)
public static java.math.BigInteger getBigInt(byte[] bytes,
int i,
int len)
public static int putBigInt(java.math.BigInteger val,
byte[] o,
int i)