Bitwise operations: Difference between revisions

Content added Content deleted
m (added solution for autoit)
(Added Wren)
Line 5,491: Line 5,491:


Visual Basic doesn't have built-in support for bitwise rotation.
Visual Basic doesn't have built-in support for bitwise rotation.

=={{header|Wren}}==
In Wren all numbers are represented in 64-bit floating point form.

Although the same bitwise operators are supported as in C, the operands are converted to unsigned 32-bit integers before the operation is performed and return values of this form.

Consequently, it is not usually a good idea to try and perform bitwise operations on integer values outside this range or on non-integral values.

Given this limitation, there is no difference between logical and arithmetic left and right shift operations. Although Wren doesn't support circular shift operators, it is not difficult to write functions to perform them.
<lang ecmascript>var rl = Fn.new { |x, y| x << y | x >> (32-y) }

var rr = Fn.new { |x, y| x >> y | x << (32-y) }

var bitwise = Fn.new { |x, y|
if (!x.isInteger || !y.isInteger || x < 0 || y < 0 || x > 0xffffffff || y > 0xffffffff) {
Fiber.abort("Operands must be in the range of a 32-bit unsigned integer")
}
System.print(" x = %(x)")
System.print(" y = %(y)")
System.print(" x & y = %(x & y)")
System.print(" x | y = %(x | y)")
System.print(" x ^ y = %(x ^ y)")
System.print("~x = %(~x)")
System.print(" x << y = %(x << y)")
System.print(" x >> y = %(x >> y)")
System.print(" x rl y = %(rl.call(x, y))")
System.print(" x rr y = %(rr.call(x, y))")
}

bitwise.call(10, 2)</lang>

{{out}}
<pre>
x = 10
y = 2
x & y = 2
x | y = 10
x ^ y = 8
~x = 4294967285
x << y = 40
x >> y = 2
x rl y = 40
x rr y = 2147483650
</pre>


=={{header|x86 Assembly}}==
=={{header|x86 Assembly}}==