Bitwise operations: Difference between revisions

Content added Content deleted
(→‎{{header|Visual Basic .NET}}: ++ x86 asm (this task belongs to cpus, really:D))
(→‎{{header|OCaml}}: ++ gnu octave)
Line 511: Line 511:
Printf.printf "a lsr b: %d\n" (a lsr b); (* logical right shift *)
Printf.printf "a lsr b: %d\n" (a lsr b); (* logical right shift *)
;;</lang>
;;</lang>

=={{header|Octave}}==

There's no arithmetic shift nor rotation (and the not can be done through a xor)

<lang octave>function bitops(a, b)
s = sprintf("%s %%s %s = %%s\n", dec2bin(a), dec2bin(b));
printf(s, "or", dec2bin(bitor(a, b)));
printf(s, "and", dec2bin(bitand(a, b)));
printf(s, "xor", dec2bin(bitxor(a, b)));
printf(s, "left shift", dec2bin(bitshift(a, abs(b))));
printf(s, "right shift", dec2bin(bitshift(a, -abs(b))));
printf("simul not %s = %s", dec2bin(a), dec2bin(bitxor(a, 0xffffffff)));
endfunction

bitops(0x1e, 0x3);</lang>


=={{header|Pascal}}==
=={{header|Pascal}}==