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

Home » Public Forums » archive » Re: Need help identifying left most zero bit
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Need help identifying left most zero bit [message #30128] Sat, 06 April 2002 22:01 Go to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Pavel Romashkin (pavel_romashkin@hotmail.com) writes:

> BTW, I have a colleague (who introduced me to IDL 3 yrs ago) whom I referred
> to your site a couple of times. He now goes there no matter what he needs.
> And he complains to me if he can't find something! Can you imagine.

Yeah, I can imagine. In fact, I'm going to start
complaining to you about it too. :-)

Cheers,

David
--
David W. Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: Need help identifying left most zero bit [message #30129 is a reply to message #30128] Sat, 06 April 2002 20:39 Go to previous messageGo to next message
Pavel Romashkin is currently offline  Pavel Romashkin
Messages: 166
Registered: April 1999
Senior Member
"David Fanning" <david@dfanning.com> wrote

> Really!? You found that function on my page?

Yeah, you know. Sometimes one can find something useful even there :-)
BTW, I have a colleague (who introduced me to IDL 3 yrs ago) whom I referred
to your site a couple of times. He now goes there no matter what he needs.
And he complains to me if he can't find something! Can you imagine.
Cheers,
Pavel
Re: Need help identifying left most zero bit [message #30130 is a reply to message #30129] Sat, 06 April 2002 15:02 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Pavel Romashkin (pavel_romashkin@hotmail.com) writes:

> Download the last function from David's page here:
> http://www.dfanning.com/misc_tips/binary_hex.html
> Then try:
>
> print, (where(binary(-15s) eq 0))[0]

Really!? You found that function on my page?

I was going to write an answer to this question,
then I thought "Why bother? You would only
embarrass yourself." I'm glad to know I figured
something like it out, once upon a time. :-)

Cheers,

David
--
David W. Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: Need help identifying left most zero bit [message #30131 is a reply to message #30130] Sat, 06 April 2002 12:43 Go to previous messageGo to next message
Pavel Romashkin is currently offline  Pavel Romashkin
Messages: 166
Registered: April 1999
Senior Member
Phil,
Download the last function from David's page here:
http://www.dfanning.com/misc_tips/binary_hex.html
Then try:

print, (where(binary(-15s) eq 0))[0]

Cheers,
Pavel

"Phil" <plmcelwee@yahoo.com> wrote in message
news:a3589d11.0204051007.10df5da6@posting.google.com...
> I'm working with negative (two's complement) 16-bit numbers and could
> use some help. What I'd like to do is have a function that will tell
> me the location of the left-most zero bit for any given negative
> 16-bit number. Here are some examples to illustrate my goal.
>
> if x = -2, which is 1111 1111 1111 1110, then return 1
> if x = -5, which is 1111 1111 1111 1011, then return 3
> if x = -15, which is 1111 1111 1111 0111, then return 4
> if x = -8, which is 1111 1111 1111 1000, then return 3
>
> Is there something built-in to IDL that will accomplish this? Or does
> anyone have any other suggestions?
Re: Need help identifying left most zero bit [message #30152 is a reply to message #30131] Fri, 05 April 2002 11:40 Go to previous messageGo to next message
TFE is currently offline  TFE
Messages: 11
Registered: November 2001
Junior Member
Phil,

think this is close-

x=-8
for i=0,15 do begin
y = UINT(ISHFT(-x-1,i)) ; 2's comp to swap bits, start left shift and check
leftmost bit
if ((y AND '8000'X) EQ '8000'X) then begin
print, 'position =', 16-i
i=15 ; exit loop
endif
endfor

"Phil" <plmcelwee@yahoo.com> wrote in message
news:a3589d11.0204051007.10df5da6@posting.google.com...
> I'm working with negative (two's complement) 16-bit numbers and could
> use some help. What I'd like to do is have a function that will tell
> me the location of the left-most zero bit for any given negative
> 16-bit number. Here are some examples to illustrate my goal.
>
> if x = -2, which is 1111 1111 1111 1110, then return 1
> if x = -5, which is 1111 1111 1111 1011, then return 3
> if x = -15, which is 1111 1111 1111 0111, then return 4
> if x = -8, which is 1111 1111 1111 1000, then return 3
>
> Is there something built-in to IDL that will accomplish this? Or does
> anyone have any other suggestions?
Re: Need help identifying left most zero bit [message #30219 is a reply to message #30128] Tue, 09 April 2002 16:53 Go to previous message
plmcelwee is currently offline  plmcelwee
Messages: 6
Registered: April 2002
Junior Member
Thanks to all for the help. These options got the job done nicely. :)


David Fanning <david@dfanning.com> wrote in message news:<MPG.17198eb31ab954f1989871@news.frii.com>...
> Pavel Romashkin (pavel_romashkin@hotmail.com) writes:
>
>> BTW, I have a colleague (who introduced me to IDL 3 yrs ago) whom I referred
>> to your site a couple of times. He now goes there no matter what he needs.
>> And he complains to me if he can't find something! Can you imagine.
>
> Yeah, I can imagine. In fact, I'm going to start
> complaining to you about it too. :-)
>
> Cheers,
>
> David
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Interfacing the functions
Next Topic: Does IDL have a #include functionality

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

Current Time: Fri Oct 10 13:37:17 PDT 2025

Total time taken to generate the page: 1.04135 seconds