Bitwise operations: Difference between revisions

→‎{{header|COBOL}}: updated for COBOL 2023; the reserved-words for the syntax highlighting need to be updated
imported>Arakov
imported>Acediast
(→‎{{header|COBOL}}: updated for COBOL 2023; the reserved-words for the syntax highlighting need to be updated)
Line 2,848:
;;There is no built-in for rotation.</syntaxhighlight>
=={{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.
PROGRAM-ID. bitwise-ops.
REMARKS. "COBOL 2023 required".
 
DATA DIVISION.
Line 2,856 ⟶ 2,858:
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.
Line 2,880 ⟶ 2,881:
DISPLAY "a exclusive-or b is " result-disp
 
*> Shift and *>rotation COBOLoperators doeswere notonly haveadded shiftin orCOBOL rotation operators2023.
 
GOBACKCOMPUTE 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}}
<syntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
Line 2,925 ⟶ 2,940:
DISPLAY "Logical implication of a and b is " result
 
GOBACK.
 
END PROGRAM mf-bitwise-ops.</syntaxhighlight>
 
=={{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
Anonymous user