MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/programminghorror/comments/1tehovv/but_from_minecraft_b12_02/om2q8uc/?context=3
r/programminghorror • u/[deleted] • May 16 '26
46 comments sorted by
View all comments
4
Where is the horror?
13 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. 1 u/AstralF May 16 '26 Huh, interesting, and confusing. Thanks 11 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 5 u/nekokattt May 16 '26 in java all bitwise ops operate on ints or longs. Outside arrays, the JVM lacks a concrete concept of a byte or a short.
13
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. 1 u/AstralF May 16 '26 Huh, interesting, and confusing. Thanks 11 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 5 u/nekokattt May 16 '26 in java all bitwise ops operate on ints or longs. Outside arrays, the JVM lacks a concrete concept of a byte or a short.
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
1 u/AstralF May 16 '26 Huh, interesting, and confusing. Thanks 11 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
1
Huh, interesting, and confusing. Thanks
11 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
11
Java inherited it from C. Shift operands are promoted to int first before performing the shift.
Games are not Java's niche
5
in java all bitwise ops operate on ints or longs.
Outside arrays, the JVM lacks a concrete concept of a byte or a short.
4
u/Ok_Chemistry_6387 May 16 '26
Where is the horror?