binary summation with exact precision
I am using following code to do binary summation:
class dump{
public static void main(String[] args){
final int number0 = Integer.parseInt("000", 2);
final int number1 = Integer.parseInt("1", 2);
final int sum = number0 + number1;
System.out.println(Integer.toBinaryString(sum));
}
}
The problem is that I do not get the exact precision of the answer - eg
000 + 1 or 00 + 1 both resolve to answer as 1.
Since I intend to use the result as the key in a hashmap ,the
non-uniqueness of the result is a problem.
How do I get 00+1=>01 or 000+1 =>001.
No comments:
Post a Comment