title: Best way to implement bitwise operations for n-byte integers
body: <p>I want to implement an efficient library for bitwise operations on big integers. I've written the following function that overrides <code>BTEST</code>:</p>
  
  <pre><code>FUNCTION testb_i2b(n,i)
    INTEGER(I8B), DIMENSION(0:), INTENT(IN) :: n
    INTEGER(I2B), INTENT(IN) :: i
    INTEGER(I2B) :: j
    LOGICAL :: testb_i2b
    j = ISHFT(i,-6)
    IF ( j .LE. UBOUND(n,1) ) THEN
      testb_i2b = BTEST(n(j),i-ISHFT(j,6))
    ELSE
      testb_i2b = .FALSE.
    END IF
  END FUNCTION testb_i2b
  </code></pre>
  
  <p>The array <code>n</code> contains the <code>64*(SIZE(n)-1)</code> bits of my big integer. Is there a more efficient way to obtain the same functionality?</p>