So, I'm reading about casts which is a subject that I find odd and was wondering if anyone knew of a resource where I could find say a table or explicit list of what primitives require an explicit cast statement when their operated on ie
Ideally I'd like to print the sucker out and stick it on my wall next to my Precedence of Operators table. Any ideas? [ June 17, 2008: Message edited by: Tristan Rouse ]
The simplest rule to follow with primitive casting is that the result of an arithmetic operation(excluding ++ & -- operators) will atleast be of type int or of the larger primitive type used in the operation.
Please don't ask new questions on somebody else's thread.
If you write out the bits for 130 in 16 bits, which are the same as a long only with fewer 0s, you get 0000 0000 1000 0010. When you cast to a byte you lose all but the rightmost 8 bits, leaving 1000 0010. In two's complement that is -126.
If you want any more information please start a new thread. [ June 25, 2008: Message edited by: Campbell Ritchie ]