位元組數組實用程式
public class ByteArrayUtil
extends Object
java.lang.Object | |
↳ | com.android.tradefed.util.ByteArrayUtil |
對位元組數組進行操作的實用程序,例如將位元組轉換為整數。
Java沒有無符號值類型,因此需要擴充將儲存在4個位元組中的無符號整數轉換為長整數值,或將儲存在2個位元組中的無符號短整數值轉換為整數值。
概括
公共構造函數 | |
---|---|
ByteArrayUtil () |
公共方法 | |
---|---|
static int | getInt (byte[] bytes, int offset, int length) 從給定的位元組中取得一個整數。 |
static long | getLong (byte[] bytes, int offset, int length) 從給定的位元組中取得長整型值。 |
static String | getString (byte[] bytes, int offset, int length) 從給定的位元組中獲取字串。 |
公共構造函數
位元組數組實用程式
public ByteArrayUtil ()
公共方法
取得整數
public static int getInt (byte[] bytes, int offset, int length)
從給定的位元組中取得一個整數。
java沒有無符號值類型,因此需要擴充將儲存在2個位元組中的無符號短整數值轉換為整數值。
參數 | |
---|---|
bytes | byte :位元組數組。 |
offset | int :整數資料的起始偏移量。 |
length | int :整數資料的長度。 |
退貨 | |
---|---|
int | 給定位元組的 int 值。 |
長
public static long getLong (byte[] bytes, int offset, int length)
從給定的位元組中取得長整型值。
java沒有無符號值類型,因此需要擴充將儲存在4個位元組中的無符號整數轉換為long值。
參數 | |
---|---|
bytes | byte :位元組數組。 |
offset | int :長整數值的起始偏移量。 |
length | int :長整數值的長度。 |
退貨 | |
---|---|
long | 給定位元組的長值。 |
取得字串
public static String getString (byte[] bytes, int offset, int length)
從給定的位元組中獲取字串。
參數 | |
---|---|
bytes | byte :位元組數組。 |
offset | int :字串資料的起始偏移量。 |
length | int :字串資料的長度。 |
退貨 | |
---|---|
String |