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

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -