While doing bitwise operation on primitive types smaller than int
they are promoted to int
and after operation they are converted back to their native type.
Why can't we simply do operation on native type?
While doing bitwise operation on primitive types smaller than int
they are promoted to int
and after operation they are converted back to their native type.
Why can't we simply do operation on native type?
Common CPUs uses 32-bit number representation for that kind of arithmetical operations. That means that registers in the Arithmetic Logic Unit (ALU) of the CPU are most likely 32-bit and that's how CPU does it. It's obvious that implicit conversion happened.
Why Java does not convert it back to that "smaller" type, I have no clue. That's the question for creators of Java.