next up previous FITS Documents
Next: Alternate Encoding Interpretation Up: Discussion Previous: ASCII Encoding

Encoding Example

An example may help make this clearer. Consider a FITS HDU whose 1's complement checksum is 868229149. This number was obtained by simply accumulating the 32-bit checksum over the header and data records using 1's complement arithmetic. The CHECKSUM keyword was first initialized to the value '0000000000000000' as described in §3.8. To zero the checksum, replace the zero initialized CHECKSUM field with the complement of the accumulated checksum, 3426738146, which is equivalent to hex CC3FDFE2. The steps needed to encode this hex value into ASCII are:

Schematically:

    Byte                       Preserve byte alignment
 1  2  3  4       1  2  3  4   1  2  3  4   1  2  3  4   1  2  3  4

CC 3F DF E2  ->  33 0F 37 38  33 0F 37 38  33 0F 37 38  33 0F 37 38
+ remainder       0  3  3  2

      = hex      33 12 3A 3A  33 0F 37 38  33 0F 37 38  33 0F 37 38
 + 0 offset      30 30 30 30  30 30 30 30  30 30 30 30  30 30 30 30

      = hex      63 42 6A 6A  63 3F 67 68  63 3F 67 68  63 3F 67 68
      ASCII       c  B  j  j   c  ?  g  h   c  ?  g  h   c  ?  g  h

We further require that only ASCII alphanumerics be used by the encoding. This is purely for cosmetic reasons to improve readability. Non-alphanumeric bytes are shifted higher and lower by pairs as in the example on the top of the next page. Byte A2 (originally ASCII B) is shifted higher (to ASCII H) to balance byte B2 (originally ASCII ? being shifted lower (to ASCII 9). The same holds true in this example for the paired bytes C2 and D2. This is possible since the two sequences of ASCII punctuation characters that can occur in encoded checksums are both preceded and followed by longer sequences of ASCII alphanumeric characters as shown in Figure 1 (above).

           A      B      C      D
step    1234   1234   1234   1234

  1     cBjj   c?gh   c?gh   c?gh    initial encoded value
  2     cCjj   c>gh   c@gh   c>gh
  3     cDjj   c=gh   cAgh   c=gh
  4     cEjj   c<gh   cBgh   c<gh
  5     cFjj   c;gh   cCgh   c;gh
  6     cGjj   c:gh   cDgh   c:gh
  7     cHjj   c9gh   cEgh   c9gh      final encoded value


next up previous FITS Documents
Next: Alternate Encoding Interpretation Up: Discussion Previous: ASCII Encoding