bit ops
This commit is contained in:
@@ -192,6 +192,20 @@ END;
|
||||
print("band: {}\n", 0xFF & 0x0F);
|
||||
print("bor: {}\n", 1 | 2 | 4);
|
||||
|
||||
// Bitwise XOR
|
||||
print("bxor: {}\n", 0xFF ^ 0x0F);
|
||||
print("bxor2: {}\n", 6 ^ 3);
|
||||
|
||||
// Bitwise NOT
|
||||
print("bnot: {}\n", ~0);
|
||||
print("bnot2: {}\n", ~1);
|
||||
|
||||
// Shifts
|
||||
print("shl: {}\n", 1 << 4);
|
||||
print("shr: {}\n", 256 >> 4);
|
||||
print("shl2: {}\n", 3 << 3);
|
||||
print("shr2: {}\n", 255 >> 1);
|
||||
|
||||
// Bitwise on variables
|
||||
bv1 := 0xFF;
|
||||
bv2 := 0x0F;
|
||||
@@ -199,6 +213,27 @@ END;
|
||||
bv3 := 1;
|
||||
bv4 := 6;
|
||||
print("bor-var: {}\n", bv3 | bv4);
|
||||
print("bxor-var: {}\n", bv1 ^ bv2);
|
||||
print("shl-var: {}\n", bv3 << 4);
|
||||
print("shr-var: {}\n", bv1 >> 4);
|
||||
print("bnot-var: {}\n", ~bv2);
|
||||
|
||||
// Bitwise compound assignment
|
||||
bca := 0xFF;
|
||||
bca &= 0x0F;
|
||||
print("and-assign: {}\n", bca);
|
||||
bco := 0x0F;
|
||||
bco |= 0xF0;
|
||||
print("or-assign: {}\n", bco);
|
||||
bcx := 0xFF;
|
||||
bcx ^= 0x0F;
|
||||
print("xor-assign: {}\n", bcx);
|
||||
bcs := 1;
|
||||
bcs <<= 8;
|
||||
print("shl-assign: {}\n", bcs);
|
||||
bcr := 256;
|
||||
bcr >>= 4;
|
||||
print("shr-assign: {}\n", bcr);
|
||||
|
||||
// Modulo on variables
|
||||
mv1 := 17;
|
||||
|
||||
Reference in New Issue
Block a user