Bitwise operations: Difference between revisions

Content added Content deleted
No edit summary
Line 3,270: Line 3,270:
=={{header|FutureBasic}}==
=={{header|FutureBasic}}==
FB does not have a bitwise symbol for not, but rather uses the "not" expression. It does not support predefined bitwise symbols for rotate left and rotate right, but functions in this demo provide that capability.
FB does not have a bitwise symbol for not, but rather uses the "not" expression. It does not support predefined bitwise symbols for rotate left and rotate right, but functions in this demo provide that capability.
<lang futurebasic>
<lang futurebasic>window 1, @"Bitwise Operations", (0,0,650,270)
include "ConsoleWindow"


def fn rotl( b as long, n as long ) as long = ( ( 2^n * b) mod 256) or (b > 127)
// Set tab width for printing
def fn rotr( b as long, n as long ) as long = (b >> n mod 32) or ( b << (32-n) mod 32)
def tab 1

local fn rotl( b as long, n as long ) as long
end fn = ( ( 2^n * b) mod 256) or (b > 127)

local fn rotr( b as long, n as long ) as long
end fn = (b >> n mod 32) or ( b << (32-n) mod 32)


local fn bitwise( a as long, b as long )
local fn bitwise( a as long, b as long )
print "Input: a = "; a; " b = "; b
print @"Input: a = "; a; @" b = "; b
print
print
print "AND :", "a && b = ", bin$(a && b), ": "; a && b
print @"AND :", @"a && b = ", bin(a && b), @": "; a && b
print "NAND :", "a ^& b = ", bin$(a ^& b), ": "; a ^& b
print @"NAND :", @"a ^& b = ", bin(a ^& b), @": "; a ^& b
print "OR :", "a || b = ", bin$(a || b), ": "; a || b
print @"OR :", @"a || b = ", bin(a || b), @": "; a || b
print "NOR :", "a ^| b = ", bin$(a ^| b), ": "; a ^| b
print @"NOR :", @"a ^| b = ", bin(a ^| b), @": "; a ^| b
print "XOR :", "a ^^ b = ", bin$(a ^^ b), ": "; a ^^ b
print @"XOR :", @"a ^^ b = ", bin(a ^^ b), @": "; a ^^ b
print "NOT :", " not a = ", bin$( not a), ": "; not a
print @"NOT :", @" not a = ", bin( not a), @": "; not a
print
print
print "Left shift :", "a << b =", bin$(a << b), ": "; a << b
print @"Left shift :", @"a << b =", bin(a << b), @": "; a << b
print "Right shift :", "a >> b =", bin$(a >> b), ": "; a >> b
print @"Right shift :", @"a >> b =", bin(a >> b), @": "; a >> b
print
print
print "Rotate left :", "fn rotl( a, b ) = ", bin$(fn rotl( a, b)), ": "; fn rotl( a, b )
print @"Rotate left :", @"fn rotl( a, b ) = ", bin(fn rotl( a, b)), @": "; fn rotl( a, b )
print "Rotate right :", "fn rotr( a, b ) = ", bin$(fn rotr( a, b )),": "; fn rotr( a, b )
print @"Rotate right :", @"fn rotr( a, b ) = ", bin(fn rotr( a, b )),@": "; fn rotr( a, b )
end fn
end fn

fn bitwise( 255, 2 )
fn bitwise( 255, 2 )

</lang>
HandleEvents</lang>


Output:
Output: