How to convert bytes in binary representation to ints in Java
•
Java
I have a string [] with a byte value
String[] s = {"110","101","100","11","10","1","0"};
Recycling s, I want to get the int value from it
I am currently using it
Byte b = new Byte(s[0]); // s[0] = 110 int result = b.intValue(); // b.intValue() is returning 110 instead of 6
Since then, I've tried to get results, {6,5,4,3,2,1}
I don't know where to start What can I do?
Thank you very much The question was answered
Solution
You can use overloaded integer The parseInt (string s, int radius) method performs such conversion So you can skip byte B = new byte (s [0]); A piece of code
int result = Integer.parseInt(s[0],2); // radix 2 for binary
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
二维码