Re: Unsigned Integers - How? [message #8118 is a reply to message #8115] |
Fri, 07 February 1997 00:00   |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Folks,
I have the distinct feeling that it is Friday and a lot of
us are not taking enough exercise and getting the ol'
oxygen going to the brain.
Let me see if I can summerize this discussion without
causing any more head scratching and muttering.
If you have unsigned 16-bit integers in a file, you first
read them into *signed* 16-bit integers.
data = INTARR(100)
READU, lun, datafile, data
If the unsigned *value* is important to you, you will have
to convert this data to LONG integers with a command like
this:
data = LONG(data) AND 'FFFF'x
(Yes, those of you uncomfortable with hexadecimal numbers
may use 65535L.)
If memory is important, you probably want to throw a
TEMPORARY in there, like this:
data = LONG(TEMPORARY(data)) AND 'FFFF'x
If the unsigned *value* is not terribly important to you,
but the *relative position of the value in relation to
other values in the data* is important (e.g. maybe you
want to display the data as an image and don't care
what the *real* values are), then you can keep the
data as 16-bit integers, but you have to, as they say,
"twiddle" or change the top-most bit. This in effect
means you subtract an "offset" of -32768 from each
member of the data set.
The unsigned value 0 becomes the signed value -32768.
The unsigned value 32768 becomes the signed value 0.
The unsigned value 65535 becomes the signed value 32768.
And so forth.
According to a wonderful post by Struan Gray earlier (and
explained to me in a private e-mail posting by Mitchell
Grunes, to which I am very appreciative), this is most
easily done by a command like this:
data = TEMPORARY(data) XOR (-32768)
If you are going to use this 16-bit data set for some kind
of real-world purpose, you will have to remember that
the *real* values are offset by this -32768 amount.
There. I hope this clarifies rather than further muddles
the issue. :-)
I'm going to go play basketball with the boys and see if
I can't get a few more brain cells in gear!
David
-----------------------------------------------------------
David Fanning, Ph.D.
Fanning Software Consulting
2642 Bradbury Court, Fort Collins, CO 80521
Phone: 970-221-0438 Fax: 970-221-4762
E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com
-----------------------------------------------------------
|
|
|