Bitwise operations: Difference between revisions
Content added Content deleted
m (→{{header|Ada}}) |
|||
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. |
<lang ada>with Ada.Text_IO, Interfaces; |
||
use Ada.Text_IO, Interfaces; |
|||
procedure Bitwise is |
procedure Bitwise is |
||
subtype Byte is Unsigned_8; |
subtype Byte is Unsigned_8; |
||
package |
package Byte_IO is new Ada.Text_Io.Modular_IO (Byte); |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
begin |
begin |
||
Put_Line("A and B = "); |
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 = "); |
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 |
end Bitwise;</lang> |
||
=={{header|Aikido}}== |
=={{header|Aikido}}== |