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

Home » Public Forums » archive » Re: bit operations
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: bit operations [message #30551] Thu, 02 May 2002 11:17 Go to previous message
Liam E. Gumley is currently offline  Liam E. Gumley
Messages: 378
Registered: January 2000
Senior Member
Dominik Paul wrote:
> are there any other bit operations in IDL except shift and ishift?
> I would like to know, if a bit is set and I would like to set a bit by
> myself in a variable.

The Boolean operators in IDL (AND, NOT, OR, XOR) perform bit-wise
operations on integer arguments (BYTE, INT, LONG, etc.). To check if a
particular bit is set,

(a) SHIFT the bit into position zero
(b) Use AND to test if the bit is set

For example:

IDL> word = 35B ; bits 5, 1,and 0 are set
IDL> bit = 5
IDL> print, ishft(word, -bit) and 1B
1
IDL> bit = 4
IDL> print, ishft(word, -bit) and 1B
0

To set a particular bit, simply add the appropriate power of two:

IDL> bit = 6
IDL> tmp = word ; this variable protects the type of WORD
IDL> tmp[0] = 2
IDL> word = word + tmp ^ bit
IDL> print, ishft(word, -bit) and 1B
1

For more information, see section 2.6 of my book "Practical IDL
Programming". To earn extra credit, try coding a pair of functions named
GETBIT and SETBIT that operate on integer arguments. Better still, try
the IDL Astronomy library, because someone has probably done it already.

Cheers,
Liam.
Practical IDL Programming
http://www.gumley.com/
[Message index]
 
Read Message
Read Message
Previous Topic: Irregularly spaced tick-marks on secondary axis.
Next Topic: Need help working with large video file

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

Current Time: Fri Oct 10 14:27:31 PDT 2025

Total time taken to generate the page: 1.36139 seconds