bitwise.gno

1.67 Kb ยท 54 lines
 1package int256
 2
 3// Not sets z to the bitwise NOT of x and returns z.
 4//
 5// The bitwise NOT operation flips each bit of the operand.
 6func (z *Int) Not(x *Int) *Int {
 7	z.value.Not(&x.value)
 8	return z
 9}
10
11// And sets z to the bitwise AND of x and y and returns z.
12//
13// The bitwise AND operation results in a value that has a bit set
14// only if both corresponding bits of the operands are set.
15func (z *Int) And(x, y *Int) *Int {
16	z.value.And(&x.value, &y.value)
17	return z
18}
19
20// Or sets z to the bitwise OR of x and y and returns z.
21//
22// The bitwise OR operation results in a value that has a bit set
23// if at least one of the corresponding bits of the operands is set.
24func (z *Int) Or(x, y *Int) *Int {
25	z.value.Or(&x.value, &y.value)
26	return z
27}
28
29// Xor sets z to the bitwise XOR of x and y and returns z.
30//
31// The bitwise XOR operation results in a value that has a bit set
32// only if the corresponding bits of the operands are different.
33func (z *Int) Xor(x, y *Int) *Int {
34	z.value.Xor(&x.value, &y.value)
35	return z
36}
37
38// Rsh sets z to the result of right-shifting x by n bits and returns z.
39//
40// Right shift operation moves all bits in the operand to the right by the specified number of positions.
41// Bits shifted out on the right are discarded, and zeros are shifted in on the left.
42func (z *Int) Rsh(x *Int, n uint) *Int {
43	z.value.Rsh(&x.value, n)
44	return z
45}
46
47// Lsh sets z to the result of left-shifting x by n bits and returns z.
48//
49// Left shift operation moves all bits in the operand to the left by the specified number of positions.
50// Bits shifted out on the left are discarded, and zeros are shifted in on the right.
51func (z *Int) Lsh(x *Int, n uint) *Int {
52	z.value.Lsh(&x.value, n)
53	return z
54}