c24ee4e3cb6a164eef9219d3988f3b2a6bef2dda
[nit.git] / examples / rosettacode / bitwise_operations.nit
1 #!/usr/bin/env nit
2 #
3 # This file is part of NIT ( http://www.nitlanguage.org ).
4 # This program is public domain
5
6 # Task: Bitwise operations
7 # SEE: <http://rosettacode.org/wiki/Bitwise_operations>
8 # Without logical right shift
9 module bitwise_operations
10
11 fun bitwise(a, b: Int)
12 do
13 print "a and b: { a.bin_and(b) }"
14 print "a or b: { a.bin_or(b) }"
15 print "a xor b: { a.bin_xor(b) }"
16 print "not a: { a.bin_not }"
17 print "a << b: { a << b }"
18 print "a >> b: { a >> b }"
19 end
20
21 if args.length >= 2 then
22 bitwise(args[0].to_i, args[1].to_i)
23 else
24 print "Usage : ./bitwise_operations X X"
25 end