int edcode=Integer.parseInt(nc, 2); This will work
Unable to convert binary string to integer despite using parseInt in java
-
17-06-2023 - |
Question
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);
Solution 2
OTHER TIPS
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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow