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

# bit_and

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.bit_and(mask: F) -> F
  where a: F, one of I8, I16, I32, I64, U8, U16, U32, U64
```

Total; on an unsigned type the result is at most `a` and at most `mask` (`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

- `mask`: the other operand\, of the same type

## Returns

`F`: the bits set in both `a` and `mask`\, on the two\'s\-complement bits of the width\; on an unsigned type `result <= a` and `result <= mask`\; it never fails.

## See also

[`bit_or`](https://una-lang.org/en/docs/std/builtin/bit_or/), [`bit_xor`](https://una-lang.org/en/docs/std/builtin/bit_xor/), [`bit_not`](https://una-lang.org/en/docs/std/builtin/bit_not/)

## Example

`src/shop.una`

```una
module shop

--- The low four flags of an item, kept with a mask.
pub main() -> Unit
  uses @console: Console[print]
=
  let flags: U8 = 250
  let low = flags.bit_and(mask: 15)
  @console.print("{low}")
```

`una run .` prints:

```text
10
```

## 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).
