-->

Monday, December 19, 2016

Type Casting with Primitives



byte: 8 bits
short: 16 bits
int: 32 bits
long: 64
float: 32
double: 64

In java, through polymorphism, its possible to cast different numerals as different types. Take this for example:
int 45 = new double


This is known as Implicit casting, and the number we casted when done so implicitly is generally preserved.

You can also cast down in reverse. Known as explicit casting:
Double 43.45 = (Int) 43.45


Its important to understand that you can as you do such things however, you are effectively cutting off bits (that is, zeros and ones) from that number to make it fit as a smaller unit.

Using a unit converter online, let's see what really happens to that number.





No comments:

Post a Comment