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" |
|||
⚫ | |||
// Set tab width for printing |
|||
⚫ | |||
def tab 1 |
|||
local fn rotl( b as long, n as long ) as long |
|||
⚫ | |||
local fn rotr( b as long, n as long ) as long |
|||
⚫ | |||
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 |
print @"AND :", @"a && b = ", bin(a && b), @": "; a && b |
||
print "NAND :", "a ^& b = ", bin |
print @"NAND :", @"a ^& b = ", bin(a ^& b), @": "; a ^& b |
||
print "OR :", "a || b = ", bin |
print @"OR :", @"a || b = ", bin(a || b), @": "; a || b |
||
print "NOR :", "a ^| b = ", bin |
print @"NOR :", @"a ^| b = ", bin(a ^| b), @": "; a ^| b |
||
print "XOR :", "a ^^ b = ", bin |
print @"XOR :", @"a ^^ b = ", bin(a ^^ b), @": "; a ^^ b |
||
print "NOT :", " not a = ", bin |
print @"NOT :", @" not a = ", bin( not a), @": "; not a |
||
print |
print |
||
print "Left shift :", "a << b =", bin |
print @"Left shift :", @"a << b =", bin(a << b), @": "; a << b |
||
print "Right shift :", "a >> b =", bin |
print @"Right shift :", @"a >> b =", bin(a >> b), @": "; a >> b |
||
print |
print |
||
print "Rotate left :", "fn rotl( a, b ) = ", bin |
print @"Rotate left :", @"fn rotl( a, b ) = ", bin(fn rotl( a, b)), @": "; fn rotl( a, b ) |
||
print "Rotate right :", "fn rotr( a, b ) = ", bin |
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: |