Bitwise operations: Difference between revisions

Added uBasic/4tH version
(→‎{{header|Kotlin}}: uses pure kotlin; no java)
(Added uBasic/4tH version)
Line 2,305:
GOTO 500
</syntaxhighlight>
==={{header|uBasic/4tH}}===
{{trans|11l}}
uBasic/4tH provides the most common bitwise operations as functions. It's not too difficult to provide the arithmetic left and right shift operations.
<syntaxhighlight lang="uBasic/4tH">x = 10
y = 2
 
Print "x = "; x
Print "y = "; y
Print "NOT x = "; NOT(x)
Print "x AND y = "; AND(x, y)
Print "x OR y = "; OR(x, y)
Print "x XOR y = "; XOR(x, y)
Print "x SHL y = "; SHL(x, y)
Print "x SHR y = "; SHL(x, -y)
Print "x ROL y = "; FUNC(_rotl (x, y))
Print "x ROR y = "; FUNC(_rotr (x, y))
 
End
 
_rotr Param (2) : Return (OR(SHL(a@, -b@), SHL(a@, Info("wordsize")-b@)))
_rotl Param (2) : Return (OR(SHL(a@, b@), SHL(a@, -(Info("wordsize")-b@))))</syntaxhighlight>
{{Out}}
<pre>x = 10
y = 2
NOT x = -11
x AND y = 2
x OR y = 10
x XOR y = 8
x SHL y = 40
x SHR y = 2
x ROL y = 40
x ROR y = -9223372036854775806
 
0 OK, 0:320</pre>
 
=={{header|BASIC256}}==
<syntaxhighlight lang="basic256"># bitwise operators - floating point numbers will be cast to integer
374

edits