comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: bitwise operators in IDL?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: bitwise operators in IDL? [message #25077] Fri, 18 May 2001 15:51 Go to next message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
thompson@orpheus.nascom.nasa.gov (William Thompson) writes:

> "Rick Towler" <rtowler@u.washington.edu> writes:
>
>> Is there a built in function in IDL for the c++ bitwise operator "&" or is
>> this going to be the first DLM i write?
>
>> Rick Towler
>
>
> AND, OR, and NOT are bitwise operators.
>
> William Thompson

Which leads to some interesting confusion sometimes when they are used
as logical operators. Consider that:

255 AND 'fe'xl is false, and
NOT 2 is true

Craig

--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
Re: bitwise operators in IDL? [message #25079 is a reply to message #25077] Fri, 18 May 2001 15:03 Go to previous messageGo to next message
thompson is currently offline  thompson
Messages: 584
Registered: August 1991
Senior Member
"Rick Towler" <rtowler@u.washington.edu> writes:

> Is there a built in function in IDL for the c++ bitwise operator "&" or is
> this going to be the first DLM i write?

> Rick Towler


AND, OR, and NOT are bitwise operators.

William Thompson
Re: bitwise operators in IDL? [message #25162 is a reply to message #25077] Mon, 21 May 2001 07:41 Go to previous message
thompson is currently offline  thompson
Messages: 584
Registered: August 1991
Senior Member
Craig Markwardt <craigmnet@cow.physics.wisc.edu> writes:


> thompson@orpheus.nascom.nasa.gov (William Thompson) writes:

>> "Rick Towler" <rtowler@u.washington.edu> writes:
>>
>>> Is there a built in function in IDL for the c++ bitwise operator "&" or is
>>> this going to be the first DLM i write?
>>
>>> Rick Towler
>>
>>
>> AND, OR, and NOT are bitwise operators.
>>
>> William Thompson

> Which leads to some interesting confusion sometimes when they are used
> as logical operators. Consider that:

> 255 AND 'fe'xl is false, and
> NOT 2 is true

It's not the operators which are confusing here. They are doing exactly what
they should. Consider the following:

IDL> if 255 then print,'true' else print,'false'
true
IDL> if 'fe'xl then print,'true' else print,'false'
false
IDL> if 255 and 'fe'xl then print,'true' else print,'false'
false

IDL> if 2 then print,'true' else print,'false'
false
IDL> if not 2 then print,'true' else print,'false'
true

So, even in a boolean sense, the operators are working correctly.

What is confusing is that sometimes IDL considers all even numbers to be false,
while other times only 0 is false. Generally, this depends on whether the
number is an integer or floating point; integers use even/odd logic, while
floating point numbers use zero/nonzero logic. For example, the result for the
statement "if 2 then ..." is completely the opposite of "if 2.0 then ...". To
mess things up even further, the function KEYWORD_SET() uses zero/nonzero logic
even if the input is integer, and thus has the potential of changing the
meaning of a boolean expression. For example, consider the result of
KEYWORD_SET(NOT 1).

The behavior for integers is necessary because of the bitwise nature of the
operators, while floating point numbers are too complicated to permit such
bitwise treatment. Thus, these operators are only bitwise for integers.

It would be nice if IDL had a boolean type that could only take the values
True and False. Alternatively, one could define system variables !true and
!false,

DEFSYSV, '!TRUE', -1B
DEFSYSV, '!FALSE', 0B

and use those when setting variables meant to be boolean. (The -1B is the
bitwise opposite of 0B.)

William Thompson
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: END statement
Next Topic: Re: END statement

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Thu Oct 09 21:14:37 PDT 2025

Total time taken to generate the page: 0.08071 seconds