Why does a double of 65555 converted to byte produce a result of 19 in Kotlin?
That's because of a numerical conversion from a wider type to a type of a smaller size. The Double (IEEE 754 double precision number) has its integral part factored to the powers of two as
65555 = 217 + 24 + 22 + 20 = 65536 + 16 + 2 + 1, which is stored in binary form as (higher bits to lower):
... 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 1
When this number is converted to Byte, only its lowest 8 bits are retained:
... _ _ _ _ _ _ _ _ _ _ 0 0 0 1 0 0 1 1
And that results into 24 + 22 + 20 = 16 + 2 + 1 = 19.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With