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

Home » Public Forums » archive » Re: counting bits
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: counting bits [message #34069] Wed, 19 February 2003 21:31 Go to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
JD Smith <jdsmith@as.arizona.edu> writes:
>
> Here's a reasonably fast implementation of your proposed method for
> arrays of unsigned longs, to count the highest bit (or rather, the
> number of leading 0 bits).
>
> function leading_zeroes_reg,num
> num=[num]
> zeroes=make_array(/BYTE,DIMENSION=size(num,/DIMENSIONS),VALU E=255b)
> for i=0,31 do begin
> shft=ishft(num,-(31-i)) AND 1
> zeroes=(zeroes ne 255b)*zeroes+(zeroes eq 255b)* $
> ((shft eq 1)*i+(shft ne 1)*255b)
> endfor
> return, (zeroes eq 255b)*32+(zeroes ne 255b)*zeroes
> end

Thanks. Thinking about it further, one could probably do a pretty fast look up
table on a byte-by-byte basis, similar to the counting-bits lookup
that you presented initially.

Craig

--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: running out of memory! can all memory be restored in idl?
Next Topic: Re: howto bind shortcut key to button

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

Current Time: Fri Oct 10 14:26:19 PDT 2025

Total time taken to generate the page: 1.82290 seconds