
Basic Data Operation

This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:


Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |
Comparison |
Matching
Memory Operations
Pointers & references |
Addresses




Task

Write a routine to perform a bitwise AND, OR, and XOR on two integers, a bitwise NOT on the first integer, a left shift, right shift, right arithmetic shift, left rotate, and right rotate.

All shifts and rotates should be done on the first integer with a shift/rotate amount of the second integer.

If any operation is not available in your language, note it.




 
BitwiseOperations(INTEGER A, INTEGER B) := FUNCTION
  BitAND := A & B;
  BitOR  := A | B;
  BitXOR := A ^ B;
  BitNOT := BNOT A;
  BitSL  := A << B; 
  BitSR  := A >> B;
  DS     := DATASET([{A,B,'Bitwise AND:',BitAND},
	             {A,B,'Bitwise OR:',BitOR},
		     {A,B,'Bitwise XOR',BitXOR},
		     {A,B,'Bitwise NOT A:',BitNOT},
		     {A,B,'ShiftLeft A:',BitSL},
		     {A,B,'ShiftRight A:',BitSR}],
		     {INTEGER AVal,INTEGER BVal,STRING15 valuetype,INTEGER val});
  RETURN DS;
END;
 
BitwiseOperations(255,5);
//right arithmetic shift, left and right rotate not implemented
/* 
   OUTPUT:
   255	5	Bitwise AND:   	5
   255	5	Bitwise OR:    	255
   255	5	Bitwise XOR    	250
   255	5	Bitwise NOT A: 	-256
   255	5	ShiftLeft A:   	8160
   255	5	ShiftRight A:  	7
 
*/
 