i want to get the integer i.e decimal number corresponding to the binary string nc. However this does not happen despite using parseInt(). for eg if nc="11000101" then edcode is also having the same value instead of giving me the decimal representation of nc. Can anyone please help

String codest="11010101";
char[] codear=codest.toCharArray();
codear[4]=codear[5];
String nc= new String(codear);
int edcode=Integer.parseInt(nc);
有帮助吗?

解决方案 2

int edcode=Integer.parseInt(nc, 2); This will work

其他提示

parseInt(String s, int radix) Parses the string argument as a signed integer in the radix specified by the second argument.

From here.

Try this:

int edcode=Integer.parseInt(nc, 2);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top