please, Help me to convert String to Binary

Discuss please, Help me to convert String to Binary in the Java Development forum on Dev Articles. please, Help me to convert String to Binary Java Development forum discussing Java, JSP, J2ME. Get help with Java and all of its related languages, libraries and variations. If itís Java-related, you can discuss it here.

Hi every one,
I am new student in java programming, so I need your help

I want to takes a function as its input a string of decimal integers, each character in the string can be thought of as a decimal digit. The digit should be converted to 3-bit binary string an packed into an int.

I did the following code, but there is problem in converting 5 and 6 also I want the output like this

I could not follow your code exactly, but this code quickly runs through the calculations needed until the number is complete

Code:

import java.io.*;
public class BinaryCalculator {
private static final int maxBytes = 3;
public static void main(String[] args) {
// we use a reader to read the inputs from the keyboard
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
do {
try {
System.out.print("Type the number to parse: ");
// if the number cannot be parsed, an exception will be thrown and is catched further down
int number = Integer.parseInt(in.readLine());
int currentBit;
String result = "";
// this is where we calculate the number in the same manner as we would do by hand.
// since the maximum number of bytes are known, we can simply run through a for-loop,
// or we would have to make further calculations to figure out the size of the most-significant-bit
for (int i = maxBytes*8; i >= 0; i--) {
currentBit = 1 << i;
if (number >= currentBit) {
result += 1;
number -= currentBit;
}
else {
result += 0;
}
}
// and then printing the result to the screen
System.out.println(result);
}
// if we tried to parse a string that was not pure numbers, this will be thrown.
catch (NumberFormatException e) {
// the program exits
System.exit(0);
}
// if the reader threw an exception, something is wrong. alas, we print the stack-trace and exit
catch (IOException e) {
e.printStackTrace();
System.exit(1);
}
}
while (true);
}
}