Bitwise operations: Difference between revisions

m
Forgot to change a few variable names
(Moved PHP shift code over)
m (Forgot to change a few variable names)
Line 20:
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(Unsigned_8'Image(Shift_Left(XA, NB))); -- Left shift
Put_Line(Unsigned_8'Image(Shift_Right(XA, NB))); -- Right shift
Put_Line(Unsigned_8'Image(Shift_Right_Arithmetic(XA, NB))); -- Right Shift Arithmetic
Put_Line(Unsigned_8'Image(Rotate_Left(XA, NB))); -- Left rotate
Put_Line(Unsigned_8'Image(Rotate_Right(XA, NB))); -- Right rotate
end bitwise;</ada>
 
Line 60:
printf("a xor b: %d\n", a ^ b);
printf("not a: %d\n", ~a);
printf("a << n: %d\n", xa << nb); /* left shift */
printf("a >> n: %d\n", xa >> nb); /* arithmetic right shift */
/* convert the signed integer into unsigned, so it will perform logical shift */
unsigned int c = a;
Line 246:
Printf.printf "a xor b: %d\n" (a lxor b);
Printf.printf "not a: %d\n" (lnot a)
Printf.printf "xa lsl nb: %d\n" (a lsl b);; (* left shift *)
Printf.printf "xa asr nb: %d\n" (a asr b);; (* arithmetic right shift *)
Printf.printf "xa lsr nb: %d\n" (a lsr b);; (* logical right shift *)</ocaml>
 
=={{header|Perl}}==
Line 268:
=={{header|PHP}}==
{{incorrect|PHP}}
<php>echo '$xa << $nb: ', $xa << $nb, "\n"; // left shift
<php>$x = -3;
echo '$xa >> $nb: ', $xa >> $nb, "\n"; // arithmetic right shift</php>
$n = 1;
echo '$x << $n: ', $x << $n, "\n"; // left shift
echo '$x >> $n: ', $x >> $n, "\n"; // arithmetic right shift</php>
=={{header|Python}}==
<python>def bitwise(a, b):
Anonymous user