Bitwise operations: Difference between revisions

→‎{{header|AWK}}: gawk has compl(n) for bitwise not. OpenBSD awk also has these functions.
(→‎{{header|PARI/GP}}: move bitneg to lang)
(→‎{{header|AWK}}: gawk has compl(n) for bitwise not. OpenBSD awk also has these functions.)
Line 184:
 
=={{header|AWK}}==
Standard awk does not have bitwise operators. Gawk has built-in functions for many bitwise operations. No rotation of bits.
 
{{works with|gawk}}
 
Standard awk does not have bitwise operators.
No rotation of bits, nor bitwise not (which can be ''simulated'' through a xor)
 
<lang awk>BEGIN {
Line 195 ⟶ 194:
print n " and " p " = " and(n,p)
print n " xor " p " = " xor(n,p)
print n " << " p " = " lshift(n, p) # left shift
print n " >> " p " = " rshift(n, p) # right shift
printf "simulated not %d = 0x%08xx\n", n, xorcompl(n, 0xffffffff) # bitwise complement
}</lang>
 
[[OpenBSD]] <code>/usr/bin/awk</code> (a variant of [[nawk]]) has these same functions, with a few differences. Gawk uses 53-bit unsigned integers, but OpenBSD awk uses 32-bit signed integers. Therefore Gawk prints <code>not 11 = 0x1ffffffffffff4</code>, but OpenBSD awk prints <code>not 11 = 0xfffffff4</code>.
 
=={{header|BASIC}}==
Anonymous user