Anonymous user
Bitwise operations: Difference between revisions
→{{header|COBOL}}: Added implication and equivalence (this is entirely theoretical; only Micro Focus supports this atm)
imported>Acediast (→ISO COBOL: removed deprecated REMARKS paragraph) |
imported>Acediast (→{{header|COBOL}}: Added implication and equivalence (this is entirely theoretical; only Micro Focus supports this atm)) |
||
Line 2,848:
;;There is no built-in for rotation.</syntaxhighlight>
=={{header|COBOL}}==
COBOL 2002 added support for bitwise operations. Shift and rotation operators were added in COBOL 2023. Results are displayed in decimal.
<syntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
Line 2,858:
01 b PIC 1(32) USAGE BIT.
01 result PIC 1(32) USAGE BIT.
01 result-disp REDEFINES result
PIC S9(9) USAGE COMPUTATIONAL.
LINKAGE SECTION.
01 a-int USAGE BINARY-LONG.
Line 2,879:
COMPUTE result = a B-XOR b
DISPLAY "a exclusive-or b is " result-disp
*> More complex operations can be constructed from these.
COMPUTE result = B-NOT (a B-XOR b)
DISPLAY "Logical equivalence of a and b is " result
COMPUTE result = (B-NOT a) B-AND b
DISPLAY "Logical implication of a and b is " result
*> Shift and rotation operators were only added in COBOL 2023.
Line 2,898 ⟶ 2,906:
END PROGRAM bitwise-ops.</syntaxhighlight>
{{works with|GnuCOBOL}}
{{works with|Visual COBOL}}
In older implementations, non-standard extensions were developed as built-in subroutines.
<syntaxhighlight 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.
Line 2,918 ⟶ 2,926:
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
Line 2,941 ⟶ 2,949:
GOBACK.
=={{header|CoffeeScript}}==
|