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 #71809 is a reply to message #71716] Wed, 21 July 2010 03:33 Go to previous messageGo to previous message
Chris[6] is currently offline  Chris[6]
Messages: 84
Registered: July 2008
Member
On Jul 20, 11:40 pm, 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 attached creates an array whose ith element is 1 if the
ith bit (i.e. the 2^i component) is 1 -- confirm with an easy number
like 5 (101 in binary). So the easiest way to combine bits 1-4 would
be something like
answer = total([1, 2, 4, 8] * test[1:4])
or, more mysteriously,
answer = ishft(number, -1) and 15B

chris
[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: Sun Oct 12 14:43:02 PDT 2025

Total time taken to generate the page: 2.16043 seconds