summaryrefslogtreecommitdiff
path: root/examples/broken/bitwise.fy
blob: b124590cc3b19cc53f32f94eac5c7ff8e7d8d14a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#*
 * Examples of how to use bitwise operators
 *#

# Prints "01\n"
assert 0 == (put 1 and 0); 
assert 1 == (say 1 and 1); 

# Prints "01\n"
assert 0 == (put 0 or 0);
assert 1 == (say 0 or 1);

# Prints "01\n"
assert 0 == (put 1 xor 1);
assert 1 == (say 1 xor 0);

# Prints "-1" (see "not" operator of NASM why so)
assert (neg 1) == (say not 0);

# Prints "82\n"
assert 8 == (put 2 << 2);
assert 2 == (say 8 >> 2);

# A bit more complex, prints "9\n"
assert 9 == (say 1 << 5 >> 5 or 2 and 5 xor 8);

# Same result, but with parenthesis:
assert 9 == (say ((((1 << 5) >> 5) or 2) and 5) xor 8);

# Different parenthesis, different result: "1\n"
assert 1 == (say 1 << 5 >> 5 or 2 and (5 xor 8));