unsigned images

Paul Schlyter pausch at electra.saaf.se
Sun Feb 23 04:29:05 EST 1997


In article <5ekod7$17m at netline-fddi.jpl.nasa.gov>,
Bill Owen <wmo at wansor.jpl.nasa.gov> wrote:
 
Article: 1563 of sci.astro.fits
 
> In article <owen-ya023080002002971216070001 at news.u.washington.edu>, owen at astro.washington.edu (Russell E. Owen) writes:
> 
>> 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
 
This is non-portable, since it assumes integers are stored as
2-complement binary numbers, and ANSI FORTRAN has no such requirements
on integers.  Your code will fail on platforms using 1-complement
or sign-magnitude integer representations - not to mention BCD
representation..... yes, there are FORTRAN implementations using
BCD for integers.


 
-- 
----------------------------------------------------------------
Paul Schlyter,  Swedish Amateur Astronomer's Society (SAAF)
Grev Turegatan 40,  S-114 38 Stockholm,  SWEDEN
e-mail:  pausch at saaf.se     psr at net.ausys.se    paul at inorbit.com
WWW:     http://www.raditex.se/~pausch/    http://spitfire.ausys.se/psr/




More information about the fitsbits mailing list