+ 1
How did it become octal? Plss explain it to me. Thanks
String number = "10001"; int bnum = Integer.parseInt(number, 2); String octal = Integer.toOctalString(bnum); System.out.println(octal);
2 Respostas
+ 3
You have a string variable 'number' which stores a string representing a binary number.
Integer.parseInt(number, 2);
tells the program to parse the string to an integer value, and that the string represents a value in base 2 (binary).
At this point, bnum would store the value 17 (from base 10 viewpoint, since 10001 in binary is 17 in decimal).
Integer.toOctalString(bnum);
converts the value in bnum to a string which represents the value of bnum in octal (base 8). 17 in base 8 is 21.
+ 2
Hatsy Rei Oh I see, Thank you for explaining. I'm new in programming so I really don't know. Thanks again. :)