我有一个字符串,其中包含一系列位(如"01100011")和一些while循环中的整数.例如:
while (true) {
int i = 100;
String str = Input Series of bits
// Convert i and str to byte array
}
Run Code Online (Sandbox Code Playgroud)
现在我想要一个很好的最快方法将字符串和int转换为字节数组.到目前为止,我所做的是转换int为String然后getBytes()在两个字符串上应用该方法.但是,它有点慢.有没有其他方法可以做到(可能)比那更快?
您可以使用Java ByteBuffer类!
例
byte[] bytes = ByteBuffer.allocate(4).putInt(1000).array();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
255 次 |
| 最近记录: |