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

Home » Public Forums » archive » Re: bits into bytes
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 into bytes [message #81032 is a reply to message #81031] Wed, 01 August 2012 16:55 Go to previous message
Heinz Stege is currently offline  Heinz Stege
Messages: 189
Registered: January 2003
Senior Member
On Wed, 1 Aug 2012 15:49:21 -0700 (PDT), wlandsman wrote:

> I have to write an array of "on-off" states in which the values are stored as bits. So if I have
>
> x = [1b,0b,1b,1b,1b,0b,1b,1b]
>
> i want to convert this to a single byte value. (This is the inverse of David Fanning's bitget.pro function.)
> One way to to do this is
>
> IDL> yy = [128b,64b,32b,16b,8b,4b,2b,1b]
> IDL> print,byte( total(yy*x))
> 187b
>
> But there must be a way to do this using masking rather than multiplication. I just can't figure it out right now. (The conversion will be done for millions of bits). Thanks, --Wayne

You can use ISHFT instead of the multiplication:

print,total(ishft(x,7b-bindgen(8)),/preserve_type)

But I don't expect any advantages on use of a floating point
processor. However the /PRESERVE_TYPE option of the TOTAL function
should speed up the calculation.

Cheers, Heinz
[Message index]
 
Read Message
Read Message
Previous Topic: bits into bytes
Next Topic: imcontour no longer plotting in color

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

Current Time: Sun Oct 12 12:12:02 PDT 2025

Total time taken to generate the page: 1.59998 seconds