Help Files: Fortran77: Bits




     HELP                      June 15, 1985                  F77/BITS



              Bit Manipulation: Octal, Hexadecimal and Binary

     The built-in bit manipulation functions:

             and, or, xor, not, rshift, lshift

     are described in "man 3f bit".  That manual section  also  illus-
     trates  how  to  use  them  to set, clear, and access bits within
     words.

     Bit strings can be used in data statements:

             integer a(3)
             data a/b'1010', o'12', z'a'/

     These statements initialize the three elements of a() to the  de-
     cimal value 10 using binary, octal and hexadecimal constants.

     When using bit strings and bit manipulation, be careful  as  VAXs
     access memory bytes in a different order depending on whether the
     operand is a byte, word, long word or character string.

     Values can be printed out in octal and hex by using the  'o'  and
     'z' format terms.  The program:

                     i = 125
                     print 100, i, i, i
             100     format('  decimal:    octal:      hex:'/ i10, o10, z10 )
                     end

     prints:

               decimal:    octal:      hex:
                    125       175        7d

     The next sample  illustrates  how  to  use  the  unsigned  format
     specifier,  'su', to treat the sign as an ordinary bit and how to
     print leading blanks as zeros:

                     i = -127
                     j = 63
                     print 100, i, i, j, j
             100     format('hex:   ',su,z8.8/ 'octal: ', o11.11)
                     end

     prints:

             hex:   ffffff81
             octal: 37777777601
             hex:   0000003f
             octal: 00000000077

             


Comments to decf@euler.berkeley.edu
© 1998 UC Regents