unsigned images

Bill Owen wmo at wansor.jpl.nasa.gov
Fri Feb 21 13:09:43 EST 1997


In article <owen-ya023080002002971216070001 at news.u.washington.edu>, owen at astro.washington.edu (Russell E. Owen) writes:
> In article <5ehbog$jc1 at darkstar.ucsc.edu>, sla at hires.ucolick.org (Steve
> Allen) wrote:
> 
> >In article <owen-ya023080001902971414190001 at news.u.washington.edu>,
> >Russell E. Owen <owen at astro.washington.edu> wrote:
[snips at various places]
> >1) flip the high order bit of each pixel
> >        (if your CCD controller has DSP capability this can be done as
> >        part of the data pipeline so that you incur no delay)
> 
> Saving that, does anyone know an ANSI standard portable method of toggling
> the sign bit on a large array of 16-bit integers? I looked into it a bit
> and am embarrassed to say that I ran into a brick wall.

In ANSI Fortran, no *efficient* way.  Many compilers offer extensions such as
IBSET or MVBITS that will let you access pieces of a 16-bit integer.  VAX
has a bitwise exclusive OR, IEOR, that will do the trick:
      VALUE(I) = IEOR (VALUE(I), -32768)

You can always use addition and subtraction if you really want to keep it
ANSI standard.  This is undoubtedly less efficient, though:

      IF (VALUE(I) .GE. 0) THEN
         VALUE(I) = VALUE(I) - 32768
      ELSE
         VALUE(I) = VALUE(I) + 32768
      END IF

Just make sure the test is written as above so that 0 becomes -32768.


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.

-- Bill Owen, wmo at wansor.jpl.nasa.gov




More information about the fitsbits mailing list