Bitwise operations: Difference between revisions
Content added Content deleted
(Added Neko) |
|||
Line 3,383: | Line 3,383: | ||
c RightRotate b: f8000007 |
c RightRotate b: f8000007 |
||
</pre> |
</pre> |
||
=={{header|Neko}}== |
|||
<lang ActionScript>/** |
|||
<doc> |
|||
<h2>bitwise operations</h2> |
|||
<p>Tectonics: |
|||
<br> nekoc bitwise.neko |
|||
<br> neko bitwise</p> |
|||
</doc> |
|||
*/ |
|||
// Neko is a signed 31 bit integer VM, full 32 bit requires builtins |
|||
var int32_new = $loader.loadprim("std@int32_new", 1); |
|||
var int32_and = $loader.loadprim("std@int32_and", 2); |
|||
var int32_or = $loader.loadprim("std@int32_or", 2); |
|||
var int32_xor = $loader.loadprim("std@int32_xor", 2); |
|||
var int32_shl = $loader.loadprim("std@int32_shl", 2); |
|||
var int32_shr = $loader.loadprim("std@int32_shr", 2); |
|||
var int32_ushr = $loader.loadprim("std@int32_ushr", 2); |
|||
var int32_complement = $loader.loadprim("std@int32_complement", 1); |
|||
// Function to show bitwise operations on a,b |
|||
var bitwise = function(a, b) { |
|||
var ia = int32_new(a); |
|||
var ib = int32_new(b); |
|||
$print("Neko 32 bit integer library\n"); |
|||
$print("a AND b: ", a, " ", b, " ", int32_and(ia, ib), "\n"); |
|||
$print("a OR b: ", a, " ", b, " ", int32_or(ia, ib), "\n"); |
|||
$print("a XOR b: ", a, " ", b, " ", int32_xor(ia, ib), "\n"); |
|||
$print("ones complement a: ", a, " ", int32_complement(ia), "\n"); |
|||
$print("a SHL b: ", a, " ", b, " ", int32_shl(ia, ib), "\n"); |
|||
$print("a SHR b: ", a, " ", b, " ", int32_shr(ia, ib), "\n"); |
|||
$print("a USHR b: ", a, " ", b, " ", int32_ushr(ia, ib), "\n"); |
|||
$print("a ROL b: is not directly supported in Neko Int32\n"); |
|||
$print("a ROR b: is not directly supported in Neko Int32\n"); |
|||
$print("\nNormal Neko 31 bit signed integers\n"); |
|||
a = $int(a); |
|||
b = $int(b); |
|||
$print("a AND b: ", a, " ", b, " ", a & b, "\n"); |
|||
$print("a OR b: ", a, " ", b, " ", a | b, "\n"); |
|||
$print("a XOR b: ", a, " ", b, " ", a ^ b, "\n"); |
|||
$print("NOT a: is not directly supported in Neko syntax\n"); |
|||
$print("a SHL b: ", a, " ", b, " ", a << b, "\n"); |
|||
$print("a SHR b: ", a, " ", b, " ", a >> b, "\n"); |
|||
$print("a USHR b: ", a, " ", b, " ", a >>> b, "\n"); |
|||
$print("a ROL b: is not directly supported in Neko syntax\n"); |
|||
$print("a ROR b: is not directly supported in Neko syntax\n"); |
|||
} |
|||
// Pass command line arguments to the demo function |
|||
// initially as float, to ensure no internal bit truncation |
|||
var a = $float($loader.args[0]); |
|||
var b = $float($loader.args[1]); |
|||
if a == null a = 0; |
|||
if b == null b = 0; |
|||
bitwise(a,b);</lang> |
|||
{{out}} |
|||
<pre>prompt$ nekoc bitwise.neko |
|||
prompt$ neko bitwise 0x7fffffff 2 |
|||
Neko 32 bit integer library |
|||
a AND b: 2147483647 2 2 |
|||
a OR b: 2147483647 2 2147483647 |
|||
a XOR b: 2147483647 2 2147483645 |
|||
ones complement a: 2147483647 -2147483648 |
|||
a SHL b: 2147483647 2 -4 |
|||
a SHR b: 2147483647 2 536870911 |
|||
a USHR b: 2147483647 2 536870911 |
|||
a ROL b: is not directly supported in Neko Int32 |
|||
a ROR b: is not directly supported in Neko Int32 |
|||
Normal Neko 31 bit signed integers |
|||
a AND b: -1 2 2 |
|||
a OR b: -1 2 -1 |
|||
a XOR b: -1 2 -3 |
|||
NOT a: is not directly supported in Neko syntax |
|||
a SHL b: -1 2 -4 |
|||
a SHR b: -1 2 -1 |
|||
a USHR b: -1 2 1073741823 |
|||
a ROL b: is not directly supported in Neko syntax |
|||
a ROR b: is not directly supported in Neko syntax</pre> |
|||
=={{header|Nemerle}}== |
=={{header|Nemerle}}== |