Shr
trait Shr<T>
Source: compiler/src/builtin_docs/prelude/ops.hy The right shift operator >>.
a >> n on a type with a Shr instance calls shr(a, n). The shift
count is always an int. int and byte have builtin instances; the
int shift is arithmetic (it keeps the sign, so -8 >> 1 is -4).
Required methods#
| Name | Description |
|---|---|
shr | Returns a shifted right by n bits. |
Examples#
use tests::assert;
class Flags {
pub bits: int,
}
impl Shr for Flags {
pub fn shr(Flags a, int n) -> Flags {
return new Flags(a.bits >> n);
}
}
fn main() {
let f = new Flags(32) >> 2;
assert!(f.bits == 8);
assert!(-8 >> 1 == -4);
}