Bitwise operations: Difference between revisions

m
No edit summary
Line 3,270:
=={{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.
<lang futurebasic>window 1, @"Bitwise Operations", (0,0,650,270)
include "ConsoleWindow"
 
enddef fn rotl( b as long, n as long ) as long = ( ( 2^n * b) mod 256) or (b > 127)
// Set tab width for printing
enddef 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 )
print @"Input: a = "; a; @" b = "; b
print
print @"AND :", @"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 @"NOR :", @"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
print @"Left shift :", @"a << b =", bin$(a << b), @": "; a << b
print @"Right shift :", @"a >> b =", bin$(a >> b), @": "; a >> b
print
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 )
end fn
 
fn bitwise( 255, 2 )
 
</lang>
HandleEvents</lang>
 
Output:
416

edits