Re: [Q]: reading hexadecimal numbers from text files [message #24511] |
Mon, 02 April 2001 19:00 |
intrigue
Messages: 2 Registered: April 2001
|
Junior Member |
|
|
In article <MPG.1532c233dd7e5ef6989dbc@news.frii.com>, davidf@dfanning.com
(David Fanning) wrote:
> David Fanning (davidf@dfanning.com) writes:
>
>> I have no idea how to read 'CS' into a short integer, but
>> hexadecimal values are quite straightforward.
>
> Well, "no idea" is perhaps too strong. You can turn
> the string "CS" into a integer value like this:
>
> IDL> variable = "CS"
> IDL> var = Fix(Byte(variable), 0)
> IDL> Print, var
> 21315
>
> I'm just not sure that's what you really wanted to do. :-(
>
Yep, thats it. Didn't realise I could do that with 'Fix'. Might try
reading the manual next time ;-)
Thanks muchly,
erin
|
|
|
Re: [Q]: reading hexadecimal numbers from text files [message #24512 is a reply to message #24511] |
Mon, 02 April 2001 17:06  |
John-David T. Smith
Messages: 384 Registered: January 2000
|
Senior Member |
|
|
Erin McKay wrote:
>
> I'm working with some DICOM files that are not supported by IDL's built-in
> access functions. I've written a DICOM parser and would like to make use
> of an external DICOM dictionary. But I can't figure out how to interpret
> ASCII strings as hexadecimal coded integers (its always the little
> things...). For example, I need to read lines like:
>
> 7FE0, 0010, 'CS', 'Pixel Data'
>
> and interpret the first 3 fields as unsigned short integers. I also need
> to print these values back out as they are displayed here.
>
> Please forward replies to 'intrigue@ozemail.com.au' as well as this group.
Try the "Z" format code:
a='7FE0'+", 0010, 'CS', 'Pixel Data'" ;can't write "7FE0...
a1=0 & a2=0 & rest=''
reads,a,FORMAT='(Z,I,A)',a1,a2,rest
print,a1,a2,rest
JD
|
|
|
Re: [Q]: reading hexadecimal numbers from text files [message #24513 is a reply to message #24512] |
Mon, 02 April 2001 17:07  |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
David Fanning (davidf@dfanning.com) writes:
> I have no idea how to read 'CS' into a short integer, but
> hexadecimal values are quite straightforward.
Well, "no idea" is perhaps too strong. You can turn
the string "CS" into a integer value like this:
IDL> variable = "CS"
IDL> var = Fix(Byte(variable), 0)
IDL> Print, var
21315
I'm just not sure that's what you really wanted to do. :-(
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|
Re: [Q]: reading hexadecimal numbers from text files [message #24514 is a reply to message #24512] |
Mon, 02 April 2001 16:58  |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Erin McKay (intrigue@ozemail.com.au) writes:
>
> I'm working with some DICOM files that are not supported by IDL's built-in
> access functions. I've written a DICOM parser and would like to make use
> of an external DICOM dictionary. But I can't figure out how to interpret
> ASCII strings as hexadecimal coded integers (its always the little
> things...). For example, I need to read lines like:
>
> 7FE0, 0010, 'CS', 'Pixel Data'
>
> and interpret the first 3 fields as unsigned short integers. I also need
> to print these values back out as they are displayed here.
I have no idea how to read 'CS' into a short integer, but
hexadecimal values are quite straightforward. You use
the "Z" format to transfer the data back and forth:
IDL> variable = 0U ; Create an unsigned short integer.
IDL> Read, variable, Format='(Z4)'
: 7FE0
IDL> Help, variable
VARIABLE UINT = 32736
You do the same thing to write it out:
IDL> Print, variable, Format='(Z4)'
7FE0
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|