Java byte array conversion problem

I have a string that contains a series of bits (such as "01100011") and some integers in the while loop For example:

while (true) {
    int i = 100;
    String str = Input Series of bits

    // Convert i and str to byte array
}

Now I want a good quickest way to convert strings and ints into byte arrays So far, all I've done is convert int to string, and then apply the GetBytes () method to both strings But it's a little slow Is there any other way to do it (possibly) faster than that?

Solution

You can use Java ByteBuffer course!

example

byte[] bytes = ByteBuffer.allocate(4).putInt(1000).array();
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>