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

Home » Public Forums » archive » Re: Integer Array into Binary Array
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: Integer Array into Binary Array [message #67022] Thu, 25 June 2009 10:52
vikramivatury is currently offline  vikramivatury
Messages: 24
Registered: May 2009
Junior Member
On Jun 25, 1:50 pm, David Fanning <n...@dfanning.com> wrote:
> Vikram writes:
>> Ok, that makes sense. Is there a way of saving this binary into an
>> array? Or is the only way just printing it to the screen?
>
> There is no "binary" data format in IDL. You can certainly
> store it as a string. There are tips here for how you can
> convert your binary string back to a number:
>
>   http://www.dfanning.com/misc_tips/binary_hex.html
>
> Cheers,
>
> David
>
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")

Thanks for your help Chris and Dr. Fanning!

Best,
Vikram
Re: Integer Array into Binary Array [message #67023 is a reply to message #67022] Thu, 25 June 2009 10:50 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Vikram writes:

> Ok, that makes sense. Is there a way of saving this binary into an
> array? Or is the only way just printing it to the screen?

There is no "binary" data format in IDL. You can certainly
store it as a string. There are tips here for how you can
convert your binary string back to a number:

http://www.dfanning.com/misc_tips/binary_hex.html

Cheers,

David


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: Integer Array into Binary Array [message #67024 is a reply to message #67023] Thu, 25 June 2009 10:48 Go to previous message
Spon is currently offline  Spon
Messages: 178
Registered: September 2007
Senior Member
On Jun 25, 6:32 pm, Vikram <vikramivat...@gmail.com> wrote:
> On Jun 25, 1:16 pm, David Fanning <n...@dfanning.com> wrote:
>
>
>
>> Vikram writes:
>>> I have made use of Dr. Fanning's BINARY.PRO and I have written
>>> something:
>
>>> img = read_tiff('Resol_Test2C.tiff')
>
>>> target = lonarr(4,1280,1024)
>
>>> bin = where(img gt 0.0)
>>> num = n_elements(bin)
>>> target[bin] = img[bin]
>
>>> num = n_elements(target)
>
>>> output = lonarr(4,5,5)
>
>>> test = [343,494]
>
>>> for x=0, n_elements(test)-1  do begin
>>>    output[x] = binary(test[x],/color)
>>> endfor
>
>>> ---------
>>> But if I do a print,output I can only get the binary for the 494, not
>>> both 343 and 494 in the same array. Any ideas?
>
>> BINARY produces string output. Maybe you want this:
>
>> IDL> test = [343,494]
>> IDL> print, test, format='(b24)'
>>                101010111
>>                111101110
>
>> Cheers,
>
>> David
>
>> --
>> David Fanning, Ph.D.
>> Fanning Software Consulting, Inc.
>> Coyote's Guide to IDL Programming:http://www.dfanning.com/
>> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
>
> Ok, that makes sense. Is there a way of saving this binary into an
> array? Or is the only way just printing it to the screen?
>
> Thanks,
> Vikram

Hi Vikram,

just use the 'string' function.

a=indgen(12)
b=string(a,format='(b024)')
print,transpose(b)

Have a look at the helpfile on format codes. I know I have to read it
again every time I want to figure out which format code I need *this*
time! :-)

Cheers,
Chris
Re: Integer Array into Binary Array [message #67025 is a reply to message #67024] Thu, 25 June 2009 10:32 Go to previous message
vikramivatury is currently offline  vikramivatury
Messages: 24
Registered: May 2009
Junior Member
On Jun 25, 1:16 pm, David Fanning <n...@dfanning.com> wrote:
> Vikram writes:
>> I have made use of Dr. Fanning's BINARY.PRO and I have written
>> something:
>
>> img = read_tiff('Resol_Test2C.tiff')
>
>> target = lonarr(4,1280,1024)
>
>> bin = where(img gt 0.0)
>> num = n_elements(bin)
>> target[bin] = img[bin]
>
>> num = n_elements(target)
>
>> output = lonarr(4,5,5)
>
>> test = [343,494]
>
>> for x=0, n_elements(test)-1  do begin
>>    output[x] = binary(test[x],/color)
>> endfor
>
>> ---------
>> But if I do a print,output I can only get the binary for the 494, not
>> both 343 and 494 in the same array. Any ideas?
>
> BINARY produces string output. Maybe you want this:
>
> IDL> test = [343,494]
> IDL> print, test, format='(b24)'
>                101010111
>                111101110
>
> Cheers,
>
> David
>
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")

Ok, that makes sense. Is there a way of saving this binary into an
array? Or is the only way just printing it to the screen?

Thanks,
Vikram
Re: Integer Array into Binary Array [message #67026 is a reply to message #67025] Thu, 25 June 2009 10:16 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Vikram writes:

> I have made use of Dr. Fanning's BINARY.PRO and I have written
> something:
>
> img = read_tiff('Resol_Test2C.tiff')
>
> target = lonarr(4,1280,1024)
>
> bin = where(img gt 0.0)
> num = n_elements(bin)
> target[bin] = img[bin]
>
> num = n_elements(target)
>
> output = lonarr(4,5,5)
>
> test = [343,494]
>
> for x=0, n_elements(test)-1 do begin
> output[x] = binary(test[x],/color)
> endfor
>
> ---------
> But if I do a print,output I can only get the binary for the 494, not
> both 343 and 494 in the same array. Any ideas?

BINARY produces string output. Maybe you want this:

IDL> test = [343,494]
IDL> print, test, format='(b24)'
101010111
111101110

Cheers,

David


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: Integer Array into Binary Array [message #67027 is a reply to message #67026] Thu, 25 June 2009 10:02 Go to previous message
vikramivatury is currently offline  vikramivatury
Messages: 24
Registered: May 2009
Junior Member
On Jun 25, 12:59 pm, Vikram <vikramivat...@gmail.com> wrote:
> Hello,
>
> I was wondering if there was a way of converting an integer array into
> binary?
> For example, we have an integer array with the following:
>
> test = [1,2,3]
>
> If we convert this to a binary array, we should get:
>
> 000000000000000100000000000000100000000000000100, etc.
>
> Is this possible in IDL?
>
> Thanks,
> Vikram

I have made use of Dr. Fanning's BINARY.PRO and I have written
something:

img = read_tiff('Resol_Test2C.tiff')

target = lonarr(4,1280,1024)

bin = where(img gt 0.0)
num = n_elements(bin)
target[bin] = img[bin]

num = n_elements(target)

output = lonarr(4,5,5)

test = [343,494]

for x=0, n_elements(test)-1 do begin
output[x] = binary(test[x],/color)
endfor

---------
But if I do a print,output I can only get the binary for the 494, not
both 343 and 494 in the same array. Any ideas?

Thanks,
Vikram
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Integer Array into Binary Array
Next Topic: Saving XYOUTS

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

Current Time: Wed Oct 08 15:16:06 PDT 2025

Total time taken to generate the page: 0.00792 seconds