|
Re: Convertion from binary string to 16bit integer [message #56202 is a reply to message #56199] |
Mon, 15 October 2007 15:47  |
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  |
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  |
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
|
|
|