IonicWind Software

IWBasic => General Questions => Topic started by: Guilect on April 23, 2009, 07:13:18 PM

Title: Power operator and bitwise AND question
Post by: Guilect on April 23, 2009, 07:13:18 PM
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
Title: Re: Power operator and bitwise AND question
Post by: Ionic Wind Support Team on April 23, 2009, 07:24:17 PM
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.
Title: Re: Power operator and bitwise AND question
Post by: Guilect on April 23, 2009, 07:57:07 PM
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.