| 1 |
# shiftr(x, shift): Shift Right |
| 2 |
|
| 3 |
Logical shift right function. |
| 4 |
|
| 5 |
## Declaration |
| 6 |
|
| 7 |
### Syntax |
| 8 |
|
| 9 |
```fortran |
| 10 |
retval = shiftr(int(number), 31); |
| 11 |
integer(int32) function shiftri32(i, shift) |
| 12 |
``` |
| 13 |
|
| 14 |
### Arguments |
| 15 |
|
| 16 |
`x` is an integer input value. |
| 17 |
|
| 18 |
`shift` an unsigned integer value less than or equal to the bit size of `x`. The |
| 19 |
possible values are 7, 31, and 63. |
| 20 |
|
| 21 |
### Return values |
| 22 |
|
| 23 |
The return value is of type integer and of the same kind as `x`. |
| 24 |
|
| 25 |
## Description |
| 26 |
|
| 27 |
**shiftr(x, shift)** logically right shifts `x` by `shift` number of bits. |
| 28 |
`shiftr` shifts from MSB(**M**ost **S**ignificant **B**it) to LSB(**L**east **S**ignificant **B**it). |
| 29 |
Bits shifted from the right end i.e., LSB bits are lost. Zeroes are appended to |
| 30 |
the opposite left end. |
| 31 |
|
| 32 |
## Types |
| 33 |
|
| 34 |
Supported types in unsigned integer value `x` and unsigned integer value `shift` |
| 35 |
from (7, 31, 63) less than or equal to bit size of `x`. |
| 36 |
|
| 37 |
``` |
| 38 |
interface shiftr |
| 39 |
module procedure shiftri8, shiftri32, shiftri64 |
| 40 |
end interface |
| 41 |
|
| 42 |
contains |
| 43 |
|
| 44 |
interface |
| 45 |
integer(int8) function shiftri8(i, shift) result(r) |
| 46 |
integer(int8), intent(in) :: i |
| 47 |
integer :: shift |
| 48 |
end function |
| 49 |
|
| 50 |
integer(int32) function shiftri32(i, shift) result(r) |
| 51 |
integer(int32) :: i |
| 52 |
integer :: shift |
| 53 |
end function |
| 54 |
|
| 55 |
integer(int64) function shiftri64(i, shift) result(r) |
| 56 |
integer(int64) :: i |
| 57 |
integer :: shift |
| 58 |
end function |
| 59 |
end interface |
| 60 |
``` |
| 61 |
|
| 62 |
## Examples |
| 63 |
|
| 64 |
```fortran |
| 65 |
program intrinsics_shiftr |
| 66 |
implicit none |
| 67 |
integer, parameter :: x = kind(4) |
| 68 |
integer :: retval |
| 69 |
retval = shiftr(int(x), 7) |
| 70 |
print *, retval |
| 71 |
end program |
| 72 |
``` |
| 73 |
|
| 74 |
**Result:** |
| 75 |
|
| 76 |
``` |
| 77 |
2 |
| 78 |
``` |
| 79 |
|
| 80 |
## See Also |
| 81 |
|
| 82 |
[shiftl](shiftl.md). |