The commented out line throws the error : "illegal operand"
I would like to do just that (power and bitwise AND) in a program I am writing.
Am I doing something incorrectly?
OPENCONSOLE
def temp as INT
temp = 2
PRINT 125 & 2 * temp
PRINT 125 & 2 / temp
PRINT 125 & 2 + temp
PRINT 125 & 2 - temp
'PRINT 125 & 2 ^ temp
PRINT
PRINT "Press Any Key To Close"
DO
UNTIL INKEY$ <> ""
CLOSECONSOLE
END
See the users guide about operator precedence, use parenthesis to group.
Correct: PRINT (125 & 2) ^ temp
The & operator only works with integer types, as it would meaningless for decimal values. ^ has higher precedence than & so the compiler is trying to do this:
PRINT 125 & (2 ^ temp)
The result of a ^ operator is a DOUBLE precision number, and then you get the error from &
Paul.
Paul,
great explaination. (yes, I know, RTM (read the manual)). ;)
It turns out, that I am in fact trying to do the : PRINT 125 & (2 ^ temp)
So, I'll use this : PRINT 125 & INT(2 ^ temp)
The INT(double) returns an INT64; I can work with that.
Thanks.