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 #39960 is a reply to message #39959] Wed, 30 June 2004 07:20 Go to previous messageGo to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
sebinjapan writes:

> I am using the function (best_)binary.pro available on David Fanning's web
> page:
> http://www.dfanning.com/misc_tips/binary_hex.html
>
> I would like to know if someone already wrote the inverse function of
> binary (a function that gives you the number corresponding to its binary
> representation)?
> Something like:
> IDL> print, inv_binary(binary(76.12))
> 76.12

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. :-)


> btw: I think there is a minor error at the end of binary.pro. On little
> endian computer, it doesn't work with scalar of byte type. I think the
> last "if" test should be:
> if little_endian AND type NE 1 then $
> instead of
> if little_endian then $

Kevin Ivory gave me this little program, but I think you are
right about it. I've updated my web page with the change.
Thanks.

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
[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: Sun Oct 12 09:43:30 PDT 2025

Total time taken to generate the page: 1.52222 seconds