There is a 1-to-1 correspondence between 2's complement representation of numbers and its String representation:
2's complement representation (32 bits) String representation ---------------------------------- ----------------------- 00000000000000000000000000000000 "0" 00000000000000000000000000000001 "1" 00000000000000000000000000000010 "2" 00000000000000000000000000000011 "3" ... ... 11111111111111111111111111111111 "-1" 11111111111111111111111111111110 "-2" 11111111111111111111111111111101 "-3" ... ... |
public static String toString( int x ) { if ( x == 0 ) // Compares x against 00000000000000000000000000000000 return "0"; // Returns the ASCII code for string "0" ! else if ( x == 1 ) return "1"; else if ( x == 2 ) return "2"; ... else if ( x == 10 ) return "10"; else if ( x == 11 ) return "11"; ... else if ( x == -1 ) return "-1"; else if ( x == -2 ) return "-2"; ... } |
|