home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.fortran
- Path: sparky!uunet!charon.amdahl.com!amdahl!rtech!pacbell.com!ames!agate!dog.ee.lbl.gov!hellgate.utah.edu!lanl!cochiti.lanl.gov!jlg
- From: jlg@cochiti.lanl.gov (J. Giles)
- Subject: Re: IAND,IOR... - Thank you
- Message-ID: <1993Jan26.190831.8026@newshost.lanl.gov>
- Sender: news@newshost.lanl.gov
- Organization: Los Alamos National Laboratory
- References: <1k1dcdINNpm3@rs2.hrz.th-darmstadt.de>
- Date: Tue, 26 Jan 1993 19:08:31 GMT
- Lines: 30
-
- In article <1k1dcdINNpm3@rs2.hrz.th-darmstadt.de>, kroeker@oc1.oc.chemie.th-darmstadt.de (Martin Kroeker) writes:
- |> Many thanks to all who responded to my query about coding non-standard
- |> bit manipulation functions in fortran, especially to Eric Haug, who provided
- |> the simple (ouch !) solution in C:
- |> long btest (long *a, long *b)
- |> return(*a>>*b);
-
- This is clearly an incorrect solution. Suppose the first argument is
- eight and the second is one, this version of btest returns four - which
- is *not* the value of the bit addressed by the second argument in either
- big- or little-endian bit numbering. In little-endian, the following
- operation would be correct:
-
- long btest (long *a, long *b)
- return(*a>>*b & 1);
-
- |> After my plea for help I had finally found a clumsy solution in fortran, but
- |> this one naturally beats it easily.
-
- I've never run across a Fortran implementation which did not have
- these as operations as either intrinsic functions or operators which
- are inlined and which use the hardware instructions (if the hardware
- has them) to perform these operations. A glance at the document for
- your particular Fortran implementation would probably have revealed a
- non-clumsy Fortran solution. Certainly it's less clumsy to use a
- implementation defined extension to Fortran than to rely on C (the
- interface to which is also implementation defined and not portable).
-
- --
- J. Giles
-