#!/usr/local/bin/spar pragma annotate( summary, "bitarith" ) @( description, "Write a routine to perform a bitwise AND, OR, and XOR on" ) @( description, "two integers, a bitwise NOT on the first integer, a left" ) @( description, "shift, right shift, right arithmetic shift, left rotate," ) @( description, "and right rotate. All shifts and rotates should be done on" ) @( description, "the first integer with a shift/rotate amount of the second" ) @( description, "integer." ) @( category, "tutorials" ) @( author, "Ken O. Burtch" ) @( see_also, "http://rosettacode.org/wiki/Bitwise_operations" ); pragma license( unrestricted ); pragma software_model( shell_script ); pragma restriction( no_external_commands ); procedure bitarith is A : constant natural := 255; B : constant natural := 170; X : constant natural := 128; N : constant natural := 1; begin put( "A and B = " ) @ (A and B); new_line; put( "A or B = " ) @ (A or B); new_line; put( "A xor B = " ) @ (A xor B); new_line; new_line; put( "A << B = " ) @ ( numerics.shift_left( X, N ) ); new_line; put( "A >> B = " ) @ ( numerics.shift_right( X, N ) ); new_line; put( "A >>> B = " ) @ ( numerics.shift_right_arithmetic( X, N ) ); new_line; put( "A rotl B = " ) @ ( numerics.rotate_left( X, N ) ); new_line; put( "A rotr B = " ) @ ( numerics.rotate_right( X, N ) ); new_line; end bitarith;