Unsigned integer support in NOST 100-1.2

William Pence pence at tetra.gsfc.nasa.gov
Mon Jul 13 12:39:43 EDT 1998


In the previous debate a few years about about adding new unsigned
integer datatypes to FITS I had argued in favor of the proposal. 
However, I have since come to appreciate that the current FITS format
already fully supports unsigned integers (16 and 32 bit at least), hence
I would now oppose any change to the Standard in this regard.  FITS is
able to store unsigned 16 and 32 bit integers in an efficient format
that is easy to read and write.  This is all that is required.  The
transformation between the internal FITS representation and the  machine
representation on a particular computer of the same unsigned integer
value is trivial: flip the value of the most significant bit (bit 32 or
16) and also swap the order of the bytes on little endian machines like
IBM PCs.  

The more important issue for programmers, I believe, is that standard
FITS software like the CFITSIO library should provide a transparent
interface for reading and writing unsigned integers in FITS files.
CFITSIO provides a whole family of routines for reading or writing data
of any supported datatype, including unsigned short, unsigned int, and
unsigned long (in the C language interface) to FITS images or tables. 
When using CFITSIO, the programmer does not need to be concerned in any
way with how the data values are internally represented in the FITS
file.  All the business with setting or reading the BZERO keyword value,
etc. is all handled internally by the interface routines.

Finally, John Davis raised the objection that the BZERO keyword =
2147483648 that is used to represent unsigned 32-bit integers in FITS is
not a valid 32-bit signed integer with some particular compilers (it is
a valid signed integer value with many other compilers, however).  This
is not a problem with the FITS format itself, but instead just
illustrates that the implementation of FITS readers and writers on any
given platform must be able to deal with the limitations of that
platform.  The similar sorts of issues have to be addressed when
reading/writing FITS files in Fortran, which doesn't even support an
unsigned integer datatype at all.

-Bill Pence





More information about the fitsbits mailing list