Re: Binary (0s and 1s) output [message #41776] |
Tue, 07 December 2004 21:57 |
marc schellens[1]
Messages: 183 Registered: January 2000
|
Senior Member |
|
|
josegomez@gmx.net wrote:
> Hi!
> I'm very new to IDL, and I'm trying to convert 5 integers into a series
> of 40 logical (0/1) values. I have done this in fortran in the past
> using an internal write, and then converting each element in the output
> string into a 0 or 1. Given my limited knowledge of IDL, I tried to use
> print with a format specifier, as follows:
> IDL> print,format='(2B8.8)',0,255
> % Unexpected text in format.
> "(2B8.8)"
> ^
> % Execution halted at: $MAIN$
>
> According to my notes, the B format is there and can be used (this is
> IDL 6.0).
>
> The other problem is how to convert the (potentially!) resulting test
> string into an array of integers.
I think this printing/reading is quite ugly.
Better do something like:
bytIn = [ your byte value array]
nIn = n_elements( bytIn)
boolOut = bytarr( 8, nIn)
for bit=0,7 do begin
boolOut[ bit, *] = (bytIn and 2^bit) gt 0
endfor
boolOut[ bitnumber, inputIntegerNumber] contains now your result
HDH,
marc
|
|
|
Re: Binary (0s and 1s) output [message #41791 is a reply to message #41776] |
Tue, 07 December 2004 09:15  |
josegomez
Messages: 2 Registered: December 2004
|
Junior Member |
|
|
David Fanning wrote:
> David Fanning writes:
>
>> Well, this is new to me, but it seems to work here
>> on IDL 6.1.1 in Windows:
>>
>> IDL> print,format='(2B8.8)',0,255
>> 0000000011111111
>
> Oh, right. It does cause an error in IDL 6.0. Probably
> wasn't ready for prime time then. :-(
Hmmmm... That's what I thought. I guess I'll need to do this in 6.1,
and I can just then use the READS command to convert to an integer
array.
Many thanks for your help, all who replied!
Jose
|
|
|
Re: Binary (0s and 1s) output [message #41792 is a reply to message #41791] |
Tue, 07 December 2004 08:20  |
Benjamin Hornberger
Messages: 258 Registered: March 2004
|
Senior Member |
|
|
josegomez@gmx.net wrote:
> Hi!
> I'm very new to IDL, and I'm trying to convert 5 integers into a series
> of 40 logical (0/1) values. I have done this in fortran in the past
> using an internal write, and then converting each element in the output
> string into a 0 or 1. Given my limited knowledge of IDL, I tried to use
> print with a format specifier, as follows:
> IDL> print,format='(2B8.8)',0,255
> % Unexpected text in format.
> "(2B8.8)"
> ^
> % Execution halted at: $MAIN$
>
> According to my notes, the B format is there and can be used (this is
> IDL 6.0).
>
> The other problem is how to convert the (potentially!) resulting test
> string into an array of integers.
>
> Many thanks
>
I think the "B" format code was introduces in IDL 6.1.
Benjamin
|
|
|
Re: Binary (0s and 1s) output [message #41793 is a reply to message #41792] |
Tue, 07 December 2004 08:21  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
David Fanning writes:
> Well, this is new to me, but it seems to work here
> on IDL 6.1.1 in Windows:
>
> IDL> print,format='(2B8.8)',0,255
> 0000000011111111
Oh, right. It does cause an error in IDL 6.0. Probably
wasn't ready for prime time then. :-(
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|
Re: Binary (0s and 1s) output [message #41794 is a reply to message #41792] |
Tue, 07 December 2004 08:20  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
josegomez@gmx.net writes:
> I'm very new to IDL, and I'm trying to convert 5 integers into a series
> of 40 logical (0/1) values. I have done this in fortran in the past
> using an internal write, and then converting each element in the output
> string into a 0 or 1. Given my limited knowledge of IDL, I tried to use
> print with a format specifier, as follows:
> IDL> print,format='(2B8.8)',0,255
> % Unexpected text in format.
> "(2B8.8)"
> ^
> % Execution halted at: $MAIN$
>
> According to my notes, the B format is there and can be used (this is
> IDL 6.0).
>
> The other problem is how to convert the (potentially!) resulting test
> string into an array of integers.
Well, this is new to me, but it seems to work here
on IDL 6.1.1 in Windows:
IDL> print,format='(2B8.8)',0,255
0000000011111111
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|