Anonymous user
Bitwise operations: Difference between revisions
Added COBOL section. Corrected PL/I lang tag.
(→{{header|MATLAB}}: works for Octave too) |
(Added COBOL section. Corrected PL/I lang tag.) |
||
Line 453:
(bit-shift-right x n)
;;There is no built-in for rotation.</lang>
=={{header|COBOL}}==
Results are displayed in decimal.
<lang cobol> IDENTIFICATION DIVISION.
PROGRAM-ID. bitwise-ops.
DATA DIVISION.
LOCAL-STORAGE SECTION.
01 a PIC 1(32) USAGE BIT.
01 b PIC 1(32) USAGE BIT.
01 result PIC 1(32) USAGE BIT.
01 result-disp REDEFINES result PIC S9(9) COMP.
LINKAGE SECTION.
01 a-int USAGE BINARY-LONG.
01 b-int USAGE BINARY-LONG.
PROCEDURE DIVISION USING a-int, b-int.
MOVE FUNCTION BOOLEAN-OF-INTEGER(a-int, 32) TO a
MOVE FUNCTION BOOLEAN-OF-INTEGER(b-int, 32) TO b
COMPUTE result = a B-AND b
DISPLAY "a and b is " result-disp
COMPUTE result = a B-OR b
DISPLAY "a or b is " result-disp
COMPUTE result = B-NOT a
DISPLAY "Not a is " result-disp
COMPUTE result = a B-XOR b
DISPLAY "a exclusive-or b is " result-disp
*> COBOL does not have shift or rotation operators.
GOBACK
.</lang>
{{works with|Visual COBOL}}
<lang cobol> IDENTIFICATION DIVISION.
PROGRAM-ID. mf-bitwise-ops.
DATA DIVISION.
LOCAL-STORAGE SECTION.
01 result USAGE BINARY-LONG.
78 arg-len VALUE LENGTH OF result.
LINKAGE SECTION.
01 a USAGE BINARY-LONG.
01 b USAGE BINARY-LONG.
PROCEDURE DIVISION USING a, b.
main-line.
MOVE b TO result
CALL "CBL_AND" USING a, result, VALUE arg-len
DISPLAY "a and b is " result
MOVE b TO result
CALL "CBL_OR" USING a, result, VALUE arg-len
DISPLAY "a or b is " result
MOVE a TO result
CALL "CBL_NOT" USING result, VALUE arg-len
DISPLAY "Not a is " result
MOVE b TO result
CALL "CBL_XOR" USING a, result, VALUE arg-len
DISPLAY "a exclusive-or b is " result
MOVE b TO result
CALL "CBL_EQ" USING a, result, VALUE arg-len
DISPLAY "Logical equivalence of a and b is " result
MOVE b TO result
CALL "CBL_IMP" USING a, result, VALUE arg-len
DISPLAY "Logical implication of a and b is " result
GOBACK
.</lang>
=={{header|CoffeeScript}}==
Line 1,711 ⟶ 1,792:
=={{header|PL/I}}==
<lang pli>/* PL/I can perform bit operations on binary integers. */▼
▲/* PL/I can perform bit operations on binary integers. */
k = iand(i,j);
k = ior(i,j);
Line 1,730 ⟶ 1,810:
u = s | t; /* logical or */
u = ^ s; /* logical not */
u = s ^ t; /* exclusive or */</lang>
=={{header|Pop11}}==
|