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

Home » Public Forums » archive » Re: inverse function of binary.pro
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: inverse function of binary.pro [message #40049 is a reply to message #39959] Wed, 30 June 2004 20:49 Go to previous message
eoraptor is currently offline  eoraptor
Messages: 5
Registered: January 2004
Junior Member
David Fanning <davidf@dfanning.com> wrote in message news:<MPG.1b4c7bbaf53aac1a9897bf@news.frii.com>...
> David Fanning writes:
>
>> For something quick and dirty, how about this:
>>
>> FUNCTION Inverse_Binary, binaryNumber
>>
>> s = Size(binaryNumber, /Dimensions)
>> bn = Reform(Long(binaryNumber), 8*s[1])
>> len = N_Elements(bn)
>>
>> RETURN, Total(bn*2^Reverse(Indgen(len)))
>>
>> END
>>
>> Works for the two or three values I've tested. :-)
>
> Well, of course it doesn't work for the example *you*
> gave, but it works for all the examples *I* used. :-(
>
> Cheers,
>
> David
>
> P.S. Let's just say I *always* prefer long integers to
> floats. :-(


How about this one.
If you have an array of binary values called binArr...

powers=Lindgen(N_Elements(binArr))
answer=Floor(Total(binArr*2L^(powers),/Double))

The assumption above is the binary array prepresents powers of 2 with
respect to it's array subscript. Thus binArr[0] is the power of 2^0,
binArr[1] is 2^1, etc
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: Re: Inconsistent errors when opening itools
Next Topic: Help calling a DLL from a DLM

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

Current Time: Sat Oct 11 12:07:26 PDT 2025

Total time taken to generate the page: 0.05094 seconds