Originally posted by dolly shah:
byte x=64;
byte y=5;
byte z= (byte)(x*y);
64 * 5 = 320
The JVM treats the results of multiplications as an int, so as it does the math, it's treating it as an int in memory. So far, no problem.
In Binary, 320 = 101000000, but, a byte can only use 8 of those, so everything after the first eight digits is truncated with the cast, giving you: 01000000
If you then turn 01000000 into decimal, you get 64.
So, that's what's going on under the covers.
Pretty kewl, eh?
-Cameron McKenzie