Answer the question
In order to leave comments, you need to log in
How to work with bytes during shift operations?
There is a series of numbers with type byte
32 0x20
64 0x40
96 0x60
-128
0x80
-96 0xA0
-64 0xC0
-32 0xE0
byte b1 = (byte) 32;
b1 >>> 5;
with positive numbers all the way, we get 1,2,3 but then garbage: byte 134217724, 134217725, 134217726, 134217727.
Did I understand correctly that a virtuoso machine first converts these values to 4 bytes and only then shifts them.
How to make it move right away? those. 0xA0 (1010 000) to 0x05 (0000 0101)?
PS (b1 & 0x00FF) >>> 5) I don't want to. I want with a byte.
Answer the question
In order to leave comments, you need to log in
JLS 15.19. Shift Operators
Unary numeric promotion (§5.6.1) is performed on each operand separately.
JLS 5.6.1. Unary Numeric Promotion
Otherwise, if the operand is of compile-time type byte, short, or char, it is promoted to a value of type int by a widening primitive conversion (§5.1.2).
Those. Yes. First, all bytes are converted to ints and it won't work without a mask.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question