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

Home » Public Forums » archive » Re: Extracting bits with IDL
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: Extracting bits with IDL [message #2592 is a reply to message #2591] Mon, 18 July 1994 06:51 Go to previous messageGo to previous message
gumley is currently offline  gumley
Messages: 10
Registered: May 1993
Junior Member
In article <Ct2GM1.1780@yuma.ACNS.ColoState.EDU>,
dean@phobos.cira.colostate.edu wrote:

> We are set up to routinely collect GOES-8 GVAR data. Like with most data
> from satellites, they put information in the individual bits. Below is a C
> structure that extracts the individual bits from part of the data header which
> contains some time information. Extracting individual bits from data with IDL
> is difficult. At first I consider building an IDL structure, but IDL is
> unable to break down to bits.

IDL can actually extract bits quite easily. You just need to use the ISHFT
and AND functions. ISHFT shifts byte, integer, or longword arguments to
the left or right, and fills any vacant positions with zeros. AND performs
a bitwise AND on byte, integer, or longword arguments. For example, let's
say I have an eight bit word, and I want to extract the first 4 bits and
the last 4 bits as two separate values. To extract the leftmost 4 bits,
you would use

value = ishft( bytval, -4 )

which shifts to the right 4 positions, and fills in the space created on
the left with zeros. To get the rightmost 4 bits, you would use

value = bytval and 15

which does a bitwise AND with any bits to set to 1 in the rightmost 4
positions. You can also use shift/mask(and) operations to extract other
bit fields. For example if you wanted to extract bits 4 and 3 (bits are
typically numbered left to right in descending order i.e. bit 7 to bit 0 in
an 8 bit word), you would use

value = ishft( bytval, -3 ) and 3

I hope this helps. It is usually instructive to write a short test program
to convince yourself that it works.

Cheers,
Liam.

--
Liam E. Gumley
NASA/GSFC Climate and Radiation Branch
Greenbelt MD, USA
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: DRAW_MOTION_EVENTS
Next Topic: translating an image....

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

Current Time: Fri Oct 10 23:02:21 PDT 2025

Total time taken to generate the page: 0.40572 seconds