Conversion of a floating-point number to an integer type is done using IEEE 754 round-toward-zero mode, i.e. just removing fraction.
Convertion of long to byte simply discards all but the 8 lowest order bits. 257L is 0 ... 01 0000 0001 (64 bits)
After conversion only 8 bits left: 0000 0001, that equals to 1.
Then b % 2 = 0
And the result will be 1 + 1 + 0 = 2
( More on type conversions: https://docs.oracle.com/javase/specs/jls/se7/html/jls-5.html#jls-5.1.3 )
Ввійдіть щоб вподобати
Ввійдіть щоб прокоментувати