public class ByteUtil {
来源:互联网 发布:linux中的find命令 编辑:程序博客网 时间:2024/06/14 04:30
public class ByteUtil {
public static final int LARGE_BYTES_THRESHOLD = 2048;
public static final byte[] EMPTY_BYTES = new byte[0];
public static String toHexString(byte b) {
String s = Integer.toHexString(b);
s = "0" + s;
s = s.substring(s.length() - 2, s.length());
return s;
}
public static String toBinaryString(byte b) {
String s = Integer.toBinaryString(b);
s = "0000000" + s;
s = s.substring(s.length() - 8, s.length());
return s;
}
public static String toHexString(byte[] bytes, int length) {
if (bytes == null) {
return null;
} else {
StringBuilder builder = new StringBuilder();
for (int i = 0; i < length; i++) {
byte byte0 = bytes[i];
if (i > 0) {
builder.append(" ");
}
builder.append(toHexString(byte0));
}
return builder.toString();
}
}
public static String toHexString(byte[] bytes, int startIndex, int length) {
if (bytes == null) {
return null;
} else {
StringBuilder builder = new StringBuilder();
for (int i = 0; i < length; i++) {
byte byte0 = bytes[startIndex + i];
if (i > 0) {
builder.append(" ");
}
builder.append(toHexString(byte0));
}
return builder.toString();
}
}
public static String toIntString(byte[] bytes, int startIndex, int length) {
if (bytes == null) {
return null;
} else {
StringBuilder builder = new StringBuilder();
for (int i = 0; i < length; i++) {
byte byte0 = bytes[startIndex + i];
if (i > 0) {
builder.append(" ");
}
builder.append(byte0);
}
return builder.toString();
}
}
public static byte getBit(byte b, int bitIndex) {
assert bitIndex >= 0 && bitIndex < 8;
byte maskByte = (byte) (1 << bitIndex);
byte out = (byte) (b & maskByte);
out = (byte) (out >>> bitIndex);
return out;
}
public static boolean equals(byte[] bytes0, byte[] bytes1) {
if (bytes0 == null && bytes1 == null) {
return true;
} else if (bytes0 == null || bytes1 == null) {
return false;
}
if (bytes0.length != bytes1.length) {
return false;
}
for (int i = 0; i < bytes0.length; i++) {
if (bytes0[i] != bytes1[i]) {
return false;
}
}
return true;
}
public static byte[] merge(byte[] bytes0, byte[] bytes1) {
if (bytes0.length == 0) {
return bytes1;
} else if (bytes1.length == 0) {
return bytes0;
}
int capacity = bytes0.length + bytes1.length;
byte[] bytes = new byte[capacity];
int pos = 0;
int length = bytes0.length;
System.arraycopy(bytes0, 0, bytes, pos, length);
pos += length;
length = bytes1.length;
System.arraycopy(bytes1, 0, bytes, pos, length);
return bytes;
}
public static final byte toNegative(byte b) {
assert b >= 0;
return (byte) (b | N_SIGN_MASK);
}
public static final byte toNonNegative(byte b) {
assert b < 0;
return (byte) (b & P_SIGN_MASK);
}
public static char[] toChars(byte[] bytes) {
return ByteToChar.toChars(bytes);
}
public static final byte N_SIGN_MASK = (byte) 0x80;
public static final byte P_SIGN_MASK = (byte) 0x7F;
}
0 0
- public class ByteUtil {
- ByteUtil
- ByteUtil.java
- public class与public partial class
- public class与public partial class 区别
- public class与public partial class
- public class Object
- C# public class Person
- class CrobotApp : public CWinApp
- class CSplitterWnd :public CSplitterWnd
- class IconEditor : public QWidget
- public class MyEclipseRegister{
- C++ public class
- public class staticInter
- public class Unname2
- public class CharToByte {
- public class CharUtil {
- public class Engineer
- 【quick-x】学习笔记(官方概述)
- 卡方选择(chi-square)能用到logistic regression当中么?(一)
- 《学习OpenCV》练习3-2
- ScrollView与ListView合用(正确计算Listview的高度)的问题解决
- public class CharToByte {
- public class ByteUtil {
- public class CharUtil {
- PROPAGATION_REQUIRES_NEW 和 PROPAGATION_NESTED区别
- 【转】ARM汇编 MOV PC,LR
- Notice: Undefined variable: data in /var/www/html/bbeden/modoer/ecshop/includes/lib_base.php on line
- 《学习OpenCV》打印矩阵
- Fighting (完全背包问题)
- 理解JavaScript的caller,callee,call,apply
- 把过程与函数说透