Bitwise operations: Difference between revisions

Content added Content deleted
Line 94: Line 94:
The following program performs all required operations and prints the resulting values in base 2 for easy checking of the bit values.
The following program performs all required operations and prints the resulting values in base 2 for easy checking of the bit values.


<lang ada>with Ada.Text_Io; use Ada.Text_Io;
<lang ada>with Ada.Text_IO, Interfaces;
with Interfaces; use Interfaces;
use Ada.Text_IO, Interfaces;
procedure Bitwise is
procedure Bitwise is
subtype Byte is Unsigned_8;
subtype Byte is Unsigned_8;
package Byte_Io is new Ada.Text_Io.Modular_Io(Byte);
package Byte_IO is new Ada.Text_Io.Modular_IO (Byte);
A : Byte := 255;
B : Byte := 170;
X : Byte := 128;
N : Natural := 1;


A : constant Byte := 255;
B : constant Byte := 170;
X : constant Byte := 128;
N : constant Natural := 1;
begin
begin
Put_Line("A and B = "); Byte_Io.Put(Item => A and B, Base => 2);
Put_Line ("A and B = "); Byte_IO.Put(Item => A and B, Base => 2);
Put_Line("A or B = "); Byte_IO.Put(Item => A or B, Base => 2);
Put_Line ("A or B = "); Byte_IO.Put(Item => A or B, Base => 2);
Put_Line("A xor B = "); Byte_Io.Put(Item => A xor B, Base => 2);
Put_Line ("A xor B = "); Byte_IO.Put(Item => A xor B, Base => 2);
Put_Line("Not A = "); Byte_IO.Put(Item => not A, Base => 2);
Put_Line ("Not A = "); Byte_IO.Put(Item => not A, Base => 2);
New_Line(2);
New_Line (2);
Put_Line(Unsigned_8'Image(Shift_Left(X, N))); -- Left shift
Put_Line (Unsigned_8'Image (Shift_Left (X, N))); -- Left shift
Put_Line(Unsigned_8'Image(Shift_Right(X, N))); -- Right shift
Put_Line (Unsigned_8'Image (Shift_Right (X, N))); -- Right shift
Put_Line(Unsigned_8'Image(Shift_Right_Arithmetic(X, N))); -- Right Shift Arithmetic
Put_Line (Unsigned_8'Image (Shift_Right_Arithmetic(X, N))); -- Right Shift Arithmetic
Put_Line(Unsigned_8'Image(Rotate_Left(X, N))); -- Left rotate
Put_Line (Unsigned_8'Image (Rotate_Left (X, N))); -- Left rotate
Put_Line(Unsigned_8'Image(Rotate_Right(X, N))); -- Right rotate
Put_Line (Unsigned_8'Image (Rotate_Right (X, N))); -- Right rotate
end bitwise;</lang>
end Bitwise;</lang>


=={{header|Aikido}}==
=={{header|Aikido}}==