Type Conversion
Implicit and Explicit |
Prof. David Bernstein
|
Computer Science Department |
bernstdh@jmu.edu |
byte
(1 byte)short
(2 bytes)int
(4 bytes)long
(8 bytes)byte
to short
: pad with one byte of 0sshort
to int
: pad with two bytes of 0sint
to long
: pad with four bytes of 0s00010011 |
00000000 | 00010011 |
byte
(-19 base 10):
11101101 |
short
:
11111111 | 11101101 |
byte
):
10000000 |
short
):
00000000 | 10000000 |
short
):
11111111 | 10000000 |
float
:
double
:
float
to double
Conversions:
long
to float
Conversions:
large = large + small;