Brett's method should work.
But in case that you are not allowed to use any external libraries, you can treat the string as an array of digits and perform long division on it. So you divide the number by 2 repeatedly until you get 0 or 1 left.
You might have to write your own method to do the division on an array of digits (deal with leftovers and remainders), but it should have a pretty good run time.
Here's an example:
Lets say you have the string 163878712638127812737637876347236482.
Convert it to an array of ints (or shorts if memory is a concern).
Perform a long division by 2, keep result in a separate array and keep track of the remainder:
int[] answer = new int[input.length]; //create the answer array
String binary = "";
public void convert(input, answer){
for(int i=input.length-1;i<=0;i--) //you want to start from the left end
{
int temp = input[i]/2; //int division, disregard decimal.
answer[i] = temp;
int remainder = input[i] - temp*2; //will be 1 or 0, carry over to the next digit
if(i>0) //check if we are not at the last digit
input[i-1] += 10*remainder;
else
binary = remainder+binary; //add new bit to the left of the binary
}
if(answer_is_smaller_than_2) //check if we have 0 or 1 left, maybe just go through the answer array
binary = answer[0]+binary;// add the last digit to binary string. It is generally ok to have a 0 in the beginning, but you can easily do a check and remove the 0
else convert(answer, new int[answer.length]); //keep dividing
}
Sorry that the recursion is not very polished. I wrote it on a run.
For more information on converting decimal to binary:
http://www.wikihow.com/Convert-from-Decimal-to-Binary
Hope this helps :)