value Representation in 8 bits Repr in 16 bits
--------+----------------------------+--------------------
... ... ....
-3 11111101 1111111111111101
-2 11111110 1111111111111110
-1 11111111 1111111111111111
0 00000000 0000000000000000
1 00000001 0000000000000001
2 00000010 0000000000000010
3 00000011 0000000000000011
... ... ....
|
The computer can easily perform +, -, *, / operations on integer values when they are in 2's complement code
|
Examples:
Number (String) Representation ------------------+---------------------- "1" 00110001 "12" 00110001 00110010 |
(These are sometimes call "numerical strings")
(Because a terminal can only display characters according to their ASCII codes).
int parseInt( String s ): return the int value translated from
the input string s
String toString( int x ): return a String that represents the integral value x
|
So basically we will be studying how these methods are written.
String s = "-123";
int i;
i = Integer.parseInt( s ); // Convert number string into integer
s = Integer.toString( i ); // Convert integer value to string
|
Here in CS255, I will show you what happens inside these 2 conversion methods
I.e.: I will show you the algorithm used inside the Java conversion methods.
|