Hey,
I'm experimenting somewhat with the packing of vars, but I ran into a problem.
The code:
import java.applet.Applet;
public class bitwiseOperationsTest
extends Applet
{
public void init() {
new bitwiseOperationsTest();
}
public bitwiseOperationsTest() {
test();
}
private final void test() {
echo("value 1: "+val1);
echo("value 2: "+val2);
echo("value 3: "+val3);
//packed_data = (short)(((packed_data & ~(0x7f << 16) | val1 << 16) & ~(0x7f << 8) | val2 << 8) & ~0x7f | val3);
/** The above is the below in one line ;) **/
//packed_data = (short)(packed_data & ~(0x7f << 16) | val1 << 16);
//packed_data = (short)(packed_data & ~(0x7f << 8) | val2 << 8);
//packed_data = (short)(packed_data & ~0x7f | val3);
echo("packed: "+packed_data);
echo("new val 1: "+((packed_data >>> 16) & 0x7f)); // ALWAYS 0
echo("new val 2: "+((packed_data >>> 8) & 0x7f));
echo("new val 3: "+(packed_data & 0x7f));
}
private final void echo(String s) {
System.out.println(s);
}
private byte val1 = 45;
private byte val2 = 95;
private byte val3 = 102;
private short packed_data = 0;
}
(Don't ask why I made it an Applet, I have my reasons.
The problem is that the 'new' value 1 always is 0. value 2 and 3 are fine, but 1 always is 0. How come? Please help me.