ligo/gitlab-pages/docs/reference/bitwise.md

182 lines
3.0 KiB
Markdown
Raw Normal View History

2020-03-17 19:38:41 +04:00
---
id: bitwise-reference
title: Bitwise
description: Operations on bytes
hide_table_of_contents: true
---
import Syntax from '@theme/Syntax';
import SyntaxTitle from '@theme/SyntaxTitle';
<SyntaxTitle syntax="pascaligo">
2020-06-09 15:15:24 +04:00
function and : 'a -> nat -> nat
2020-03-17 19:38:41 +04:00
</SyntaxTitle>
<SyntaxTitle syntax="cameligo">
2020-06-09 15:15:24 +04:00
val and : 'a -> nat -> nat
2020-03-17 19:38:41 +04:00
</SyntaxTitle>
<SyntaxTitle syntax="reasonligo">
2020-06-09 15:15:24 +04:00
let and: ('a, nat) => nat
2020-03-17 19:38:41 +04:00
</SyntaxTitle>
2020-06-09 15:15:24 +04:00
`'a` can either be an `int` or `nat`.
2020-03-17 19:38:41 +04:00
A bitwise `and` operation.
2020-06-09 15:15:24 +04:00
<Syntax syntax="pascaligo">
```pascaligo
const zero: nat = Bitwise.and(2n, 1n)
```
</Syntax>
<Syntax syntax="cameligo">
```cameligo
let zero: nat = Bitwise.and 2n 1n
```
</Syntax>
<Syntax syntax="reasonligo">
```reasonligo
let zero: nat = Bitwise.and(2n, 1n);
```
</Syntax>
2020-03-17 19:38:41 +04:00
<SyntaxTitle syntax="pascaligo">
function or : nat -> nat -> nat
</SyntaxTitle>
<SyntaxTitle syntax="cameligo">
val or : nat -> nat -> nat
</SyntaxTitle>
<SyntaxTitle syntax="reasonligo">
2020-04-06 20:09:23 +04:00
let or: (nat, nat) => nat
2020-03-17 19:38:41 +04:00
</SyntaxTitle>
A bitwise `or` operation.
2020-06-09 15:15:24 +04:00
<Syntax syntax="pascaligo">
```pascaligo
const three: nat = Bitwise.or(2n, 1n)
```
</Syntax>
<Syntax syntax="cameligo">
```cameligo
let three: nat = Bitwise.or 2n 1n
```
</Syntax>
<Syntax syntax="reasonligo">
```reasonligo
let three: nat = Bitwise.or(2n, 1n);
```
</Syntax>
2020-03-17 19:38:41 +04:00
<SyntaxTitle syntax="pascaligo">
function xor : nat -> nat -> nat
</SyntaxTitle>
<SyntaxTitle syntax="cameligo">
val xor : nat -> nat -> nat
</SyntaxTitle>
<SyntaxTitle syntax="reasonligo">
2020-04-06 20:09:23 +04:00
let xor: (nat, nat) => nat
2020-03-17 19:38:41 +04:00
</SyntaxTitle>
A bitwise `xor` operation.
2020-06-09 15:15:24 +04:00
<Syntax syntax="pascaligo">
```pascaligo
2020-06-09 18:32:07 +04:00
const three: nat = Bitwise.xor(2n, 1n)
2020-06-09 15:15:24 +04:00
```
</Syntax>
<Syntax syntax="cameligo">
```cameligo
let two: nat = Bitwise.xor 2n 1n
```
</Syntax>
<Syntax syntax="reasonligo">
```reasonligo
let two: nat = Bitwise.xor(2n, 1n);
```
</Syntax>
2020-03-17 19:38:41 +04:00
<SyntaxTitle syntax="pascaligo">
function shift_left : nat -> nat -> nat
</SyntaxTitle>
<SyntaxTitle syntax="cameligo">
val shift_left : nat -> nat -> nat
</SyntaxTitle>
<SyntaxTitle syntax="reasonligo">
2020-04-06 20:09:23 +04:00
let shift_left: (nat, nat) => nat
2020-03-17 19:38:41 +04:00
</SyntaxTitle>
A bitwise shift left operation.
2020-06-09 15:15:24 +04:00
<Syntax syntax="pascaligo">
```pascaligo
const four: nat = Bitwise.shift_left(2n, 1n)
```
</Syntax>
<Syntax syntax="cameligo">
```cameligo
let four: nat = Bitwise.shift_left 2n 1n
```
</Syntax>
<Syntax syntax="reasonligo">
```reasonligo
let four: nat = Bitwise.shift_left(2n, 1n);
```
</Syntax>
2020-03-17 19:38:41 +04:00
<SyntaxTitle syntax="pascaligo">
function shift_right : nat -> nat -> nat
</SyntaxTitle>
<SyntaxTitle syntax="cameligo">
val shift_right : nat -> nat -> nat
</SyntaxTitle>
<SyntaxTitle syntax="reasonligo">
2020-04-06 20:09:23 +04:00
let shift_right: (nat, nat) => nat
2020-03-17 19:38:41 +04:00
</SyntaxTitle>
A bitwise shift right operation.
2020-06-09 15:15:24 +04:00
<Syntax syntax="pascaligo">
```pascaligo
const one: nat = Bitwise.shift_right(2n, 1n)
```
</Syntax>
<Syntax syntax="cameligo">
```cameligo
let one: nat = Bitwise.shift_right 2n 1n
```
</Syntax>
<Syntax syntax="reasonligo">
```reasonligo
let one: nat = Bitwise.shift_right(2n, 1n);
```
</Syntax>