/* Copyright (C) 2003-2015 LiveCode Ltd. This file is part of LiveCode. LiveCode is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License v3 as published by the Free Software Foundation. LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with LiveCode. If not see . */ /* This module specifies the bitwise operations on integers included in the standard library of LiveCode Builder. */ module com.livecode.bitwise use com.livecode.foreign public foreign handler MCBitwiseEvalBitwiseAnd(in Left as LCInt, in Right as LCInt, out Value as LCInt) returns nothing binds to "" public foreign handler MCBitwiseEvalBitwiseOr(in Left as LCInt, in Right as LCInt, out Value as LCInt) returns nothing binds to "" public foreign handler MCBitwiseEvalBitwiseNot(in Operand as LCInt, out Value as LCInt) returns nothing binds to "" public foreign handler MCBitwiseEvalBitwiseXor(in Left as LCInt, in Right as LCInt, out Value as LCInt) returns nothing binds to "" public foreign handler MCBitwiseEvalBitwiseShiftLeft(in Target as LCInt, in Shift as LCUInt, out Value as LCInt) returns nothing binds to "" public foreign handler MCBitwiseEvalBitwiseShiftRight(in Target as LCInt, in Shift as LCUInt, out Value as LCInt) returns nothing binds to "" -- /* Summary: Performs a bitwise AND operation on the binary representations of and . Left: An expression which evaluates to an integer. Right: An expression which evaluates to an integer. Returns: The integer whose binary representation is the result of the bitwise AND operation. Example: variable tVar as Number put 3 bitwise and 6 into tVar -- tVar contains 2 Description: Each bit of bitwise and is 1 if and only if both the corresponding bit of the binary representation of and that of is 1. Otherwise it is 0. Tags: Bitwise operations */ syntax BitwiseAnd is left binary operator with bitwise and precedence "bitwise and" begin MCBitwiseEvalBitwiseAnd(Left, Right, output) end syntax /* Summary: Performs a bitwise OR operation on the binary representations of and . Left: An expression which evaluates to an integer. Right: An expression which evaluates to an integer. Returns: The integer whose binary representation is the result of the bitwise OR operation. Example: variable tVar as Number put 3 bitwise or 6 into tVar -- tVar contains 7 Description: Each bit of bitwise or is 0 if and only if both the corresponding bit of the binary representation of and that of is 0. Otherwise it is 1. Tags: Bitwise operations */ syntax BitwiseOr is left binary operator with bitwise or precedence "bitwise or" begin MCBitwiseEvalBitwiseOr(Left, Right, output) end syntax /* Summary: Performs a bitwise XOR operation on the binary representations of and . Left: An expression which evaluates to an integer. Right: An expression which evaluates to an integer. Returns: The integer whose binary representation is the result of the bitwise XOR operation. Example: variable tVar as Number put 3 bitwise xor 6 into tVar -- tVar contains 5 Description: Each bit of bitwise xor is 1 if and only if exactly one of the corresponding bits of the binary representation of and that of is 1. Otherwise it is 0. Tags: Bitwise operations */ syntax BitwiseXor is left binary operator with bitwise xor precedence "bitwise xor" begin MCBitwiseEvalBitwiseXor(Left, Right, output) end syntax /* Summary: Performs a bitwise NOT operation on the binary representation of . Operand: An expression which evaluates to an integer. Returns: The integer whose binary representation is the result of the bitwise NOT operation. Example: variable tVar as Number put bitwise not -5 into tVar -- tVar contains 4 Description: Bitwise not returns the complement of as a signed two's complement integer, i.e. equivalent to -(x + 1). Tags: Bitwise operations */ syntax BitwiseNot is prefix operator with modifier precedence "bitwise" "not" begin MCBitwiseEvalBitwiseNot(Operand, output) end syntax -- /* Summary: Shifts the bits of left. Operand: An expression which evaluates to an integer. Shift: An expression which evaluates to an integer. Returns: The result of bit-shifting left by places. Example: variable tVar put 7 shifted left by 2 bitwise into tVar -- tVar contains 28 Description: Shifts the bits of left. Shifting the bits of left by x is equivalent to multiplying by 2^x. Tags: Bitwise operations */ syntax BitwiseShiftLeft is postfix operator with bitwise shift precedence "shifted" "left" "by" "bitwise" begin MCBitwiseEvalBitwiseShiftLeft(Operand, Shift, output) end syntax /* Summary: Shifts the bits of right. Operand: An expression which evaluates to an integer. Shift: An expression which evaluates to an integer. Returns: The result of bit-shifting right by places. Example: variable tVar put 7 shifted right by 2 bitwise into tVar -- tVar contains 1 Description: Shifts the bits of right. Shifting the bits of right by x is equivalent to dividing by 2^x (rounding down) Tags: Bitwise operations */ syntax BitwiseShiftRight is postfix operator with bitwise shift precedence "shifted" "right" "by" "bitwise" begin MCBitwiseEvalBitwiseShiftRight(Operand, Shift, output) end syntax -- //syntax BitwiseRotate is postfix operator with bitwise shift precedence // "rotated" "by" "bitwise" //begin // EvalBitwiseRotate(Operand, Shift, output) //end syntax end module