Hi Friends,
Can someone please tell me how to convert a String to a binary number
(4 digits) and then store it in a char array.
For example,if String s = 4, I need to convert them to
"0100" and then store them in a char array.
I tried this code,but I am first converting the string to integer,
and then casting it back to String,and moreover it's 3-digits and not
4.Please help
public class test{
public static void main(String[] ar){
String s = "4";
int num = Integer.parseInt(s);
s = Integer.toBinaryString(num);
System.out.println("Binary String:"+s);
char[] arr = s.toCharArray();
for(int i=0;i<arr.length;i++)
System.out.println("Char digit:"+arr);
}
}