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

Home » Public Forums » archive » Re: Convertion from binary string to 16bit integer
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: Convertion from binary string to 16bit integer [message #56199] Tue, 16 October 2007 01:01
Tal is currently offline  Tal
Messages: 26
Registered: August 2007
Junior Member
Hi again,

Thanks for all these replies.
problem solved.

cheers
Re: Convertion from binary string to 16bit integer [message #56202 is a reply to message #56199] Mon, 15 October 2007 15:47 Go to previous message
JD Smith is currently offline  JD Smith
Messages: 850
Registered: December 1999
Senior Member
On Sun, 14 Oct 2007 02:21:49 -0700, Tal wrote:

> Hi guys,
>
> Great help with this int2bin code from 2005 (1993):
> http://groups.google.com/group/comp.lang.idl-pvwave/browse_t hread/thread/61b692e9e403ef59/bdc5ce69d034eb17?hl=en&lnk =gst&q=int2bin
>
> Has anyone wrote an inverse code like bin2int or something equivalent?
> It would be generally to sum up all products of 2^i values with the
> corresponding 1's and 0's that a binary string has. (i=0,15 or 0,7 for
> example).
>
> The solution i'm looking for is for a 16bit binary string.

int=0L & reads,'1100110',FORMAT='(B)',int
print,int

I don't know how int2bin works, but it could work using string itself:

bin=string(int,FORMAT='(B0)')

JD
Re: Convertion from binary string to 16bit integer [message #56209 is a reply to message #56202] Mon, 15 October 2007 04:44 Go to previous message
Spon is currently offline  Spon
Messages: 178
Registered: September 2007
Senior Member
On Oct 15, 9:55 am, sjwelch <samjwe...@gmail.com> wrote:
> Long time reader, first time poster. Greetings to all.
>
> assuming you have a 16 character, left '0' padded string, strbin
>
> number = total((byte(strbin) - 48b) * (2L ^ reverse(bindgen(16))))
>
> that's what IDL does best ;) sure there's a simpler way too...
>
> On Oct 14, 8:21 pm, Tal <t...@bar-kal.com> wrote:
>
>> Hi guys,
>
>> Great help with this int2bin code from 2005 (1993):http://groups.google.com/group/comp.lang.idl-pvwave/b rowse_thread/thr...
>
>> Has anyone wrote an inverse code like bin2int or something equivalent?
>> It would be generally to sum up all products of 2^i values with the
>> corresponding 1's and 0's that a binary string has. (i=0,15 or 0,7 for
>> example).
>
>> The solution i'm looking for is for a 16bit binary string.
>
>> Cheers,
>> Tal

Hi

I may be barking completely up the wrong tree, but is this what you
want?

Arr = BYTE (BinaryString) - 48
Els = N_ELEMENTS (Arr)

Result = TOTAL (2^ LINDGEN (Els) * Arr )

all the best
Chris
Re: Convertion from binary string to 16bit integer [message #56212 is a reply to message #56209] Mon, 15 October 2007 01:55 Go to previous message
sjwelch is currently offline  sjwelch
Messages: 5
Registered: October 2007
Junior Member
Long time reader, first time poster. Greetings to all.

assuming you have a 16 character, left '0' padded string, strbin

number = total((byte(strbin) - 48b) * (2L ^ reverse(bindgen(16))))

that's what IDL does best ;) sure there's a simpler way too...

On Oct 14, 8:21 pm, Tal <t...@bar-kal.com> wrote:
> Hi guys,
>
> Great help with this int2bin code from 2005 (1993):http://groups.google.com/group/comp.lang.idl-pvwave/b rowse_thread/thr...
>
> Has anyone wrote an inverse code like bin2int or something equivalent?
> It would be generally to sum up all products of 2^i values with the
> corresponding 1's and 0's that a binary string has. (i=0,15 or 0,7 for
> example).
>
> The solution i'm looking for is for a 16bit binary string.
>
> Cheers,
> Tal
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: for loop elimination
Next Topic: ENVI ROUTINES

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

Current Time: Wed Oct 08 13:52:04 PDT 2025

Total time taken to generate the page: 0.00535 seconds