Bitwise operations: Difference between revisions
Content added Content deleted
(→{{header|Smalltalk}}: Visual Basic) |
(Modula-3) |
||
Line 435: | Line 435: | ||
MAXScript doesn't have arithmetic shift or rotate operations. |
MAXScript doesn't have arithmetic shift or rotate operations. |
||
=={{header|Modula-3}}== |
|||
<pre> |
|||
MODULE Bitwise EXPORTS Main; |
|||
IMPORT IO, Fmt, Word; |
|||
VAR c: Word.T; |
|||
PROCEDURE Bitwise(a, b: INTEGER) = |
|||
BEGIN |
|||
IO.Put("a AND b: " & Fmt.Int(Word.And(a, b)) & "\n"); |
|||
IO.Put("a OR b: " & Fmt.Int(Word.Or(a, b)) & "\n"); |
|||
IO.Put("a XOR b: " & Fmt.Int(Word.Xor(a, b)) & "\n"); |
|||
IO.Put("NOT a: " & Fmt.Int(Word.Not(a)) & "\n"); |
|||
c := a; |
|||
IO.Put("c LeftShift b: " & Fmt.Unsigned(Word.LeftShift(a, b)) & "\n"); |
|||
IO.Put("c RightShift b: " & Fmt.Unsigned(Word.RightShift(a, b)) & "\n"); |
|||
IO.Put("c LeftRotate b: " & Fmt.Unsigned(Word.LeftRotate(a, b)) & "\n"); |
|||
IO.Put("c RightRotate b: " & Fmt.Unsigned(Word.RightRotate(a, b)) & "\n"); |
|||
END Bitwise; |
|||
BEGIN |
|||
Bitwise(255, 5); |
|||
END Bitwise. |
|||
</pre> |
|||
Output: |
|||
<pre> |
|||
a AND b: 5 |
|||
a OR b: 255 |
|||
a XOR b: 250 |
|||
NOT a: -256 |
|||
c LeftShift b: 1fe0 |
|||
c RightShift b: 7 |
|||
c LeftRotate b: 1fe0 |
|||
c RightRotate b: f8000007 |
|||
</pre> |
|||
=={{header|OCaml}}== |
=={{header|OCaml}}== |