unsigned images

Russell E. Owen owen at astro.washington.edu
Wed Feb 26 14:00:25 EST 1997


In article <5ekod7$17m at netline-fddi.jpl.nasa.gov>, wmo at wansor.jpl.nasa.gov
(Bill Owen) wrote:
>...
>In ANSI C, however, the problem is trivial.  Use the bitwise exclusive OR
>operator, and the one statement
>      value[i] ^= 0x8000;
>will flip the sign bit and leave the rest alone.  (Yes, I realize that one
>would probably code it up using a pointer instead of a subscript.)  The bit
>pattern 0x8000 -- sign bit on, others off -- is -32768 on two's complement
>machines.
>
>No matter how you do it, BZERO should be set to +32768.

Thank you very much. I was sure I was missing something, and you nailed it.
(I actually considered XOR but missed an important detail that made it
work.)

So for FITS output my plan is to:
- convert the internal data in place (saves copying it to another array)
- write it out in one operation
- convert it back again
using appropriate exception handling to be sure the internal representation
actually DOES get converted back.
(Storing the data internally as signed data is less efficient, as every
image will have to be converted even if it's never written out as a FITS
file).

If anyone has alternative suggestions, feel free to comment. Having missed
the XOR solution it seems possible I'm overlooking something equally simple
for the rest of the problem.

Regards,

-- Russell




More information about the fitsbits mailing list