Bitwise operations: Difference between revisions

Content added Content deleted
imported>Arakov
imported>Acediast
(→‎{{header|COBOL}}: updated for COBOL 2023; the reserved-words for the syntax highlighting need to be updated)
Line 2,848: Line 2,848:
;;There is no built-in for rotation.</syntaxhighlight>
;;There is no built-in for rotation.</syntaxhighlight>
=={{header|COBOL}}==
=={{header|COBOL}}==
===ISO COBOL===
Results are displayed in decimal.
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.
<syntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. bitwise-ops.
PROGRAM-ID. bitwise-ops.
REMARKS. "COBOL 2023 required".


DATA DIVISION.
DATA DIVISION.
Line 2,856: Line 2,858:
01 a PIC 1(32) USAGE BIT.
01 a PIC 1(32) USAGE BIT.
01 b PIC 1(32) USAGE BIT.
01 b PIC 1(32) USAGE BIT.

01 result PIC 1(32) USAGE BIT.
01 result PIC 1(32) USAGE BIT.
01 result-disp REDEFINES result PIC S9(9) COMP.
01 result-disp REDEFINES result PIC S9(9) COMP.
Line 2,880: Line 2,881:
DISPLAY "a exclusive-or b is " result-disp
DISPLAY "a exclusive-or b is " result-disp


*> COBOL does not have shift or rotation operators.
*> Shift and rotation operators were only added in COBOL 2023.


GOBACK
COMPUTE result = a B-SHIFT-L b
DISPLAY "a shifted left by b is " result-disp
.</syntaxhighlight>


COMPUTE result = b B-SHIFT-R a
DISPLAY "b shifted right by a is " result-disp

COMPUTE result = a B-SHIFT-LC b
DISPLAY "a rotated left by b is " result-disp

COMPUTE result = b B-SHIFT-RC a
DISPLAY "b rotated right by a is " result-disp

GOBACK.

END PROGRAM bitwise-ops.</syntaxhighlight>

===Visual COBOL===
{{works with|Visual COBOL}}
{{works with|Visual COBOL}}
<syntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
<syntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
Line 2,925: Line 2,940:
DISPLAY "Logical implication of a and b is " result
DISPLAY "Logical implication of a and b is " result


GOBACK
GOBACK.

.</syntaxhighlight>
END PROGRAM mf-bitwise-ops.</syntaxhighlight>

=={{header|CoffeeScript}}==
=={{header|CoffeeScript}}==
CoffeeScript provides sugar for some JavaScript operators, but the bitwise operators are taken directly from JS. See more here: http://coffeescript.org/#operators
CoffeeScript provides sugar for some JavaScript operators, but the bitwise operators are taken directly from JS. See more here: http://coffeescript.org/#operators