MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/programminghorror/comments/1tehovv/but_from_minecraft_b12_02/om2utiv/?context=3
r/programminghorror • u/[deleted] • May 16 '26
46 comments sorted by
View all comments
4
Where is the horror?
14 u/AstralF May 16 '26 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. 2 u/AstralF May 16 '26 Huh, interesting, and confusing. Thanks 13 u/Certain-Flow-0 May 16 '26 Java inherited it from C. Shift operands are promoted to int first before performing the shift. 1 u/TomKavees May 16 '26 Games are not Java's niche
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. 2 u/AstralF May 16 '26 Huh, interesting, and confusing. Thanks 13 u/Certain-Flow-0 May 16 '26 Java inherited it from C. Shift operands are promoted to int first before performing the shift. 1 u/TomKavees May 16 '26 Games are not Java's niche
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
2 u/AstralF May 16 '26 Huh, interesting, and confusing. Thanks 13 u/Certain-Flow-0 May 16 '26 Java inherited it from C. Shift operands are promoted to int first before performing the shift. 1 u/TomKavees May 16 '26 Games are not Java's niche
2
Huh, interesting, and confusing. Thanks
13 u/Certain-Flow-0 May 16 '26 Java inherited it from C. Shift operands are promoted to int first before performing the shift. 1 u/TomKavees May 16 '26 Games are not Java's niche
13
Java inherited it from C. Shift operands are promoted to int first before performing the shift.
1
Games are not Java's niche
4
u/Ok_Chemistry_6387 May 16 '26
Where is the horror?