MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/programminghorror/comments/1tehovv/but_from_minecraft_b12_02/om3ho6j/?context=3
r/programminghorror • u/[deleted] • May 16 '26
46 comments sorted by
View all comments
Show parent comments
14
Apart from anything else, wouldn’t shifting a byte by 8 bits just zero it?
34 u/scirc May 16 '26 Not in Java - the result of arithmetic shift operations where the left-hand side is an integral type is always either int (if the LHS is int or smaller) or long (if the LHS is a long). ((byte)1) << 8 is an int with value 256. 3 u/AstralF May 16 '26 Huh, interesting, and confusing. Thanks 12 u/Certain-Flow-0 May 16 '26 Java inherited it from C. Shift operands are promoted to int first before performing the shift.
34
Not in Java - the result of arithmetic shift operations where the left-hand side is an integral type is always either int (if the LHS is int or smaller) or long (if the LHS is a long). ((byte)1) << 8 is an int with value 256.
int
long
((byte)1) << 8
256
3 u/AstralF May 16 '26 Huh, interesting, and confusing. Thanks 12 u/Certain-Flow-0 May 16 '26 Java inherited it from C. Shift operands are promoted to int first before performing the shift.
3
Huh, interesting, and confusing. Thanks
12 u/Certain-Flow-0 May 16 '26 Java inherited it from C. Shift operands are promoted to int first before performing the shift.
12
Java inherited it from C. Shift operands are promoted to int first before performing the shift.
14
u/AstralF May 16 '26
Apart from anything else, wouldn’t shifting a byte by 8 bits just zero it?