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

Home » Public Forums » archive » Re: bits from bytes --> DANGEROUS when used in IF
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: bits from bytes --> DANGEROUS when used in IF [message #10652] Mon, 22 December 1997 00:00
Martin Schultz is currently offline  Martin Schultz
Messages: 515
Registered: August 1997
Senior Member
Robert Moss wrote:
>
> Kelly Dean wrote:
>>
>> I need to extract the first 3 bits from a byte.
>>
>> Any suggestions?
>>

[...]

> b = 11B ; a byte of data

[...] individual bit.

> If what you want is the first three bits together,
> it would simply be ( b AND 7 ) = 3
>


Be careful with this expression in IF statements !
This can be very dangerous, because of IDL's handling of TRUE and FALSE
values. Often, what you want to do is something like
if (bit_set(b)) then ...
Now try
if ( b AND 7 ) then print,"GREAT !"

This will work for b=11B, but not for b=10B !

The solution is :
if ((b AND 7) gt 0) then print,"GREATER !"

Martin.


------------------------------------------------------------ -------
Dr. Martin Schultz
Department for Earth&Planetary Sciences, Harvard University
186 Pierce Hall, 29 Oxford St., Cambridge, MA-02138, USA

phone: (617)-496-8318
fax : (617)-495-4551

e-mail: mgs@io.harvard.edu
IDL-homepage: http://www-as.harvard.edu/people/staff/mgs/idl/
------------------------------------------------------------ -------
[Message index]
 
Read Message
Previous Topic: GROUP_LEADER (before I start my holidays ...)
Next Topic: IRIX/Linux binary compatibility?

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

Current Time: Sat Oct 11 13:50:07 PDT 2025

Total time taken to generate the page: 0.56192 seconds