u256
Expand description
256-bit unsigned integer
Implementations
pub fn min() -> Self
pub fn min() -> Self
The smallest value that can be represented by this integer type.
Returns
- [u256] - The smallest
u256
value.
Examples
fn foo() {
let val = u256::min();
assert(val == 0x0000000000000000000000000000000000000000000000000000000000000000u256);
pub fn max() -> Self
pub fn max() -> Self
The largest value that can be represented by this integer type,
2256 - 1.
Returns
- [u256] - The largest
u256
value.
Examples
fn foo() {
let val = u256::max();
assert(val == 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFu256);
}
pub fn bits() -> u64
pub fn bits() -> u64
The size of this integer type in bits.
Returns
- [u32] - The number of bits for a
u256
.
Examples
fn foo() {
let bits = u256::bits();
assert(bits == 256);
}
pub fn zero() -> Self
pub fn zero() -> Self
Returns the zero value for the u256
type.
Returns
- [u256] -> The zero value for the
u256
type.
Examples
fn foo() {
let zero_u256 = u256::zero();
assert(zero_u256 == 0x00u256);
}
pub fn as_b256(self) -> b256
pub fn as_b256(self) -> b256
Converts a u256
to a b256
.
Returns
- [b256] - The converted
u256
value.
Examples
fn foo() {
let val: u256 = 0x0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20u256;
let result = val.as_b256();
assert(result == 0x0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20);
}
Trait Implementations
impl Eq for u256
impl Eq for u256
pub fn eq(self, other: Self) -> bool
pub fn neq(self, other: Self) -> bool
pub fn neq(self, other: Self) -> bool
Evaluates if two values of the same type are not equal.
Additional Information
This function is inherited when eq()
is implemented.
Arguments
other
: [Self] - The value of the same type.
Returns
- [bool] -
true
if the two values are not equal, otherwisefalse
.
Examples
struct MyStruct {
val: u64,
}
impl Eq for MyStruct {
fn eq(self, other: Self) -> bool {
self.val == other.val
}
}
fn foo() {
let struct1 = MyStruct { val: 10 };
let struct2 = MyStruct { val: 2 };
let result = struct1 != struct2;
assert(result);
}
impl BitwiseAnd for u256
impl BitwiseAnd for u256
pub fn binary_and(self, other: Self) -> Self
impl BitwiseXor for u256
impl BitwiseXor for u256
pub fn binary_xor(self, other: Self) -> Self
impl OrdEq for u256
impl OrdEq for u256
pub fn ge(self, other: Self) -> bool
pub fn ge(self, other: Self) -> bool
Evaluates if one value of the same type is greater or equal to than another.
Additional Information
This trait requires that the Ord
and Eq
traits are implemented.
Arguments
other
: [Self] - The value of the same type.
Returns
- [bool] -
true
ifself
is greater than or equal toother
, otherwisefalse
.
Examples
struct MyStruct {
val: u64,
}
impl Eq for MyStruct {
fn eq(self, other: Self) -> bool {
self.val == other.val
}
}
impl Ord for MyStruct {
fn gt(self, other: Self) -> bool {
self.val > other.val
}
}
impl OrdEq for MyStruct {}
fn foo() {
let struct1 = MyStruct { val: 10 };
let struct2 = MyStruct { val: 10 };
let result = struct1 >= struct2;
assert(result);
}
pub fn le(self, other: Self) -> bool
pub fn le(self, other: Self) -> bool
Evaluates if one value of the same type is less or equal to than another.
Additional Information
This trait requires that the Ord
and Eq
traits are implemented.
Arguments
other
: [Self] - The value of the same type.
Returns
- [bool] -
true
ifself
is less than or equal toother
, otherwisefalse
.
Examples
struct MyStruct {
val: u64,
}
impl Eq for MyStruct {
fn eq(self, other: Self) -> bool {
self.val == other.val
}
}
impl Ord for MyStruct {
fn lt(self, other: Self) -> bool {
self.val < other.val
}
}
impl OrdEq for MyStruct {}
fn foo() {
let struct1 = MyStruct { val: 10 };
let struct2 = MyStruct { val: 10 };
let result = struct1 <= struct2;
assert(result);
}