---
title: "shift_right"
url: https://una-lang.org/en/docs/std/builtin/shift_right/
release: v0.4.0
edition: "0.2 and later"
source: https://github.com/una-lang/una/blob/v0.4.0/docs/std/builtins.json
---

# shift_right

A built-in method, resolved by the type of its receiver ([`spec/14 §2`](https://una-lang.org/en/docs/spec/14-standard-library/#s2)). Edition 0.2 and later.

```una
a.shift_right(by: Int) -> F
  where a: F, one of I8, I16, I32, I64, U8, U16, U32, U64
```

Requires `0 <= by` and `by` below the width; on an unsigned type the result is at most `a`. On a signed type it divides by `2^by`, rounding toward negative infinity (`spec/18 §5`).

## Receiver

- `F, one of I8, I16, I32, I64, U8, U16, U32, U64`: a fixed\-width integer `a`\, of one of the eight types `I8`\, `I16`\, `I32`\, `I64`\, `U8`\, `U16`\, `U32` and `U64`\; the result has its type

## Parameters

- `by`: the number of places\, an `Int`

## Returns

`F`: `a` divided by `2^by`\, rounding toward negative infinity\: on a signed type the shift is arithmetic\, so a negative value stays negative\; on an unsigned type `result <= a`.

## Requires

- `0 <= by and by < w`: the number of places is at least `0` and below the width `w` of the type\, `8` for `I8` and `U8` up to `64` for `I64` and `U64`

Each condition under `requires` is an obligation at every call\, which `una check` proves \(`spec/12 §3`\)\: it reports U5001 when the condition is refuted and U5002 when it is unknown \(`spec/12 §6`\)\, and `una run`\, `una test` and `una build` refuse a package with an obligation that is not proved \(`spec/22 §2`\)\.

## See also

[`wrapping_shift_left`](https://una-lang.org/en/docs/std/builtin/wrapping_shift_left/)

## Example

`src/shop.una`

```una
module shop

--- A debt halved, a count divided by eight, and the same debt shifted by seven places.
pub main() -> Unit
  uses @console: Console[print]
=
  let debt: I8 = -128
  let half = debt.shift_right(by: 1)
  let units: U16 = 1000
  let eighth = units.shift_right(by: 3)
  let whole = debt.shift_right(by: 7)
  @console.print("{half}")
  @console.print("{eighth}")
  @console.print("{whole}")
```

`una run .` prints:

```text
-64
125
-1
```

## Specification

- [`spec/18 §5`](https://una-lang.org/en/docs/spec/18-fixed-width-integers/#s5)

Generated from una v0.4.0 ([`docs/std/builtins.json`](https://github.com/una-lang/una/blob/5fec93d88932b333feec25e589355a2cb34c37b5/docs/std/builtins.json), which is not part of the specification): built-in methods have no declaration, so una writes these signature lines and tests each against its checker. The specification governs: [`spec/14 §2`](https://una-lang.org/en/docs/spec/14-standard-library/#s2).
