Reverse the four bytes of an int32.
Written with ibits/ishft using only non-negative shift counts.
ishft with a negative count is avoided because the compilers this
project targets have historically disagreed about it, and shiftr is
Fortran 2008 which is more than this needs to assume.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer(kind=int32), | intent(in) | :: | x |
pure function bswap_int32(x) result(y) !! Reverse the four bytes of an `int32`. !! !! Written with `ibits`/`ishft` using only non-negative shift counts. !! `ishft` with a negative count is avoided because the compilers this !! project targets have historically disagreed about it, and `shiftr` is !! Fortran 2008 which is more than this needs to assume. integer(int32), intent(in) :: x integer(int32) :: y y = ior(ior(ishft(ibits(x, 0, BITS_PER_BYTE), 24), ishft(ibits(x, 8, BITS_PER_BYTE), 16)), & ior(ishft(ibits(x, 16, BITS_PER_BYTE), 8), ibits(x, 24, BITS_PER_BYTE))) end function bswap_int32