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

Home » Public Forums » archive » Decomposing a bit field?
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: Decomposing a bit field? [message #71810 is a reply to message #71716] Wed, 21 July 2010 03:31 Go to previous messageGo to previous message
greg.addr is currently offline  greg.addr
Messages: 160
Registered: May 2007
Senior Member
On 21 Jul., 11:40, Rob <rj...@le.ac.uk> wrote:
> Hi all,
>
> I have some data that is contained within a 32-bit field.
>
> I'm using some code from a colleague which seems to almost do what I
> want but not quite.
>
> An example of one of the data values is 15982561
>
> The following code takes this and creates an array of 1s and 0s for
> whether each bit is set or not.
>
> test=intarr(32)
> for i=0, 31 do begin test[i]=(ISHFT((15982561),-i) AND 1B)
>
> However, for example bits 1-4 need to be combined (and contain data
> from 0-15). As I don't quite understand what the code above is doing
> I'm not sure how to (or if it can be) modified to not just operate on
> the individual bits but on groups of bits.
>
> What I need to extract is the information in the folowing form:
>
> Bit 0:  0 or 1
> Bits 1-4: 0-15
> Bit 5: 0 or 1
> Bits 6-8: 0-8
> etc
>
> Thanks in advance

The code you have is progressively shifting the bits to the right
(i.e. dividing by 2^i) and copying the resulting least significant bit
into the test array. You can achieve what you want with something like
this:

IDL> a=15982561
IDL> print,(a and ishft(1,indgen(32))) gt 0 ;decomposition like yours
(least significant on the left)
1 0 0 0 0 1 1 1 1 1 1 1 1 0 1 1 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

IDL> bit=[0,1,5,6] ;start bit for each group
IDL> n_bits=[1,4,1,3] ;no. of bits in each
IDL> print,2^n_bits-1 ;max values for each group
1 15 1 7
IDL> print,2^n_bits-1 and ishft(a,-bit) ;the result
1 0 1 7

regards,
Greg
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Read these data in structure
Next Topic: Re: Read these data in structure

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

Current Time: Wed Dec 03 08:53:53 PST 2025

Total time taken to generate the page: 2.24539 seconds