|
||||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
java.lang.Objectcom.hankcs.hanlp.utility.ByteUtil
public class ByteUtil
对数字和字节进行转换。
基础知识:
假设数据存储是以大端模式存储的:
byte: 字节类型 占8位二进制 00000000
char: 字符类型 占2个字节 16位二进制 byte[0] byte[1]
int : 整数类型 占4个字节 32位二进制 byte[0] byte[1] byte[2] byte[3]
long: 长整数类型 占8个字节 64位二进制 byte[0] byte[1] byte[2] byte[3] byte[4] byte[5]
byte[6] byte[7]
float: 浮点数(小数) 占4个字节 32位二进制 byte[0] byte[1] byte[2] byte[3]
double: 双精度浮点数(小数) 占8个字节 64位二进制 byte[0] byte[1] byte[2] byte[3] byte[4]
byte[5] byte[6] byte[7]
| 构造方法摘要 | |
|---|---|
ByteUtil()
|
|
| 方法摘要 | |
|---|---|
static char |
bytesHighFirstToChar(byte[] bytes,
int start)
字节数组转char,高位在前,适用于读取writeChar的数据 |
static double |
bytesHighFirstToDouble(byte[] bytes,
int start)
读取double,高位在前 |
static float |
bytesHighFirstToFloat(byte[] bytes,
int start)
读取float,高位在前 |
static int |
bytesHighFirstToInt(byte[] bytes,
int start)
字节数组和整型的转换,高位在前,适用于读取writeInt的数据 |
static long |
bytesHighFirstToLong(byte[] b)
|
static char |
bytesToChar(byte[] b)
将一个2位字节数组转换为char字符。 |
static double |
bytesToDouble(byte[] b)
将一个8位字节数组转换为双精度浮点数。 |
static float |
bytesToFloat(byte[] b)
将一个4位字节数组转换为浮点数。 |
static int |
bytesToInt(byte[] b)
将一个4位字节数组转换为4整数。 |
static int |
bytesToInt(byte[] bytes,
int start)
字节数组和整型的转换 |
static long |
bytesToLong(byte[] b)
将一个8位字节数组转换为长整数。 |
static byte[] |
charToBytes(char c)
将一个char字符转换位字节数组(2个字节),b[0]存储高位字符,大端 |
static char[] |
convertIntToTwoChar(int n)
|
static int |
convertTwoCharToInt(char high,
char low)
|
static byte[] |
doubleToBytes(double d)
将一个双精度浮点数转换位字节数组(8个字节),b[0]存储高位字符,大端 |
static byte[] |
floatToBytes(float f)
将一个浮点数转换为字节数组(4个字节),b[0]存储高位字符,大端 |
static byte[] |
intToBytes(int i)
将一个整数转换位字节数组(4个字节),b[0]存储高位字符,大端 |
static byte[] |
longToBytes(long l)
将一个长整数转换位字节数组(8个字节),b[0]存储高位字符,大端 |
static void |
writeUnsignedInt(DataOutputStream out,
int uint)
无符号整型输出 |
| 从类 java.lang.Object 继承的方法 |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| 构造方法详细信息 |
|---|
public ByteUtil()
| 方法详细信息 |
|---|
public static char bytesToChar(byte[] b)
b - 字节数组
public static double bytesToDouble(byte[] b)
b - 字节数组
public static double bytesHighFirstToDouble(byte[] bytes,
int start)
bytes - start -
public static float bytesToFloat(byte[] b)
b - 字节数组
public static int bytesToInt(byte[] b)
b - 字节数组
public static long bytesToLong(byte[] b)
b - 字节数组
public static long bytesHighFirstToLong(byte[] b)
public static byte[] charToBytes(char c)
c - 字符(java char 2个字节)
public static byte[] doubleToBytes(double d)
d - 双精度浮点数
public static byte[] floatToBytes(float f)
f - 浮点数
public static byte[] intToBytes(int i)
i - 整数
public static byte[] longToBytes(long l)
l - 长整数
public static int bytesToInt(byte[] bytes,
int start)
bytes - 字节数组
public static int bytesHighFirstToInt(byte[] bytes,
int start)
bytes - 字节数组
public static char bytesHighFirstToChar(byte[] bytes,
int start)
bytes - start -
public static float bytesHighFirstToFloat(byte[] bytes,
int start)
bytes - start -
public static void writeUnsignedInt(DataOutputStream out,
int uint)
throws IOException
out - uint -
IOException
public static int convertTwoCharToInt(char high,
char low)
public static char[] convertIntToTwoChar(int n)
|
||||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||