string - How to convert a byte in binary representation into int in java -
i have string[] byte values
string[] s = {"110","101","100","11","10","1","0"};
looping through s, want int values out of it.
i using this
byte b = new byte(s[0]); // s[0] = 110 int result = b.intvalue(); // b.intvalue() returning 110 instead of 6
from that, trying results, {6, 5, 4, 3, 2, 1}
i not sure of go here. can do?
thanks guys. question answered.
you can use overloaded integer.parseint(string s, int radix)
method such conversion. way can skip byte b = new byte(s[0]);
piece of code.
int result = integer.parseint(s[0], 2); // radix 2 binary
Comments
Post a Comment