I am trying to figure out how I would take all the odd numbers in a file and convert them to binary 1 and the even numbers in the file and change them to binary 0. I am creating a binary search tree and I need to do the following for each element. - Decide if the element is even or odd, if even concatenate a 0 to my string, if odd concatenate a 1. -This will then build a binary String that represents a LONG -Then I want to convert the binary string to a long using these;
new BigInteger {myString}
longValue();
Heres an example of the file:
1973
3522
3465
1825
701
4842
2457
2895
746
4367
This is what Ive got so far. To find the odd and then the even #'s
public void convert (TreeNode<E> node){
for(int i = 1; i <= size(); i++){
if (i % 2 == 0){
}
}
for(int i = 2; i <= size(); i++){
if (i % 2 != 0){
}
}
}
So how would I convert the numbers to binary code and how would I convert the binary string to a long. Please anything will help Thanks!