문제

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