Rosettacode: Add Bitwise Op.
authorMATYSIAK Herve <herve.matysiak@viacesi.fr>
Wed, 10 Jun 2015 18:26:38 +0000 (14:26 -0400)
committerJean Privat <jean@pryen.org>
Tue, 16 Jun 2015 19:45:54 +0000 (15:45 -0400)
Close #1488

examples/rosettacode/bitwise_operations.nit [new file with mode: 0644]
tests/bitwise_operations.args [new file with mode: 0644]
tests/sav/bitwise_operations.res [new file with mode: 0644]
tests/sav/bitwise_operations_args1.res [new file with mode: 0644]

diff --git a/examples/rosettacode/bitwise_operations.nit b/examples/rosettacode/bitwise_operations.nit
new file mode 100644 (file)
index 0000000..c24ee4e
--- /dev/null
@@ -0,0 +1,25 @@
+#!/usr/bin/env nit
+#
+# This file is part of NIT ( http://www.nitlanguage.org ).
+# This program is public domain
+
+# Task: Bitwise operations
+# SEE: <http://rosettacode.org/wiki/Bitwise_operations>
+# Without logical right shift
+module bitwise_operations
+
+fun bitwise(a, b: Int)
+do
+       print "a and b: { a.bin_and(b) }"
+       print "a or b: { a.bin_or(b) }"
+       print "a xor b: { a.bin_xor(b) }"
+       print "not a: { a.bin_not }"
+       print "a << b: { a << b }"
+       print "a >> b: { a >> b }"
+end
+
+if args.length >= 2 then
+       bitwise(args[0].to_i, args[1].to_i)
+else
+       print "Usage : ./bitwise_operations X X"
+end
diff --git a/tests/bitwise_operations.args b/tests/bitwise_operations.args
new file mode 100644 (file)
index 0000000..795ed34
--- /dev/null
@@ -0,0 +1 @@
+5 10
diff --git a/tests/sav/bitwise_operations.res b/tests/sav/bitwise_operations.res
new file mode 100644 (file)
index 0000000..f84a553
--- /dev/null
@@ -0,0 +1 @@
+Usage : ./bitwise_operations X X
diff --git a/tests/sav/bitwise_operations_args1.res b/tests/sav/bitwise_operations_args1.res
new file mode 100644 (file)
index 0000000..b08e14f
--- /dev/null
@@ -0,0 +1,6 @@
+a and b: 0
+a or b: 15
+a xor b: 15
+not a: -6
+a << b: 5120
+a >> b: 0