Primitive std::u32

u32
Expand description
32-bit unsigned integer

Implementations

fn is_zero(self) -> bool

Returns whether a u32 is set to zero.

Returns

  • [bool] -> True if the u32 is zero, otherwise false.

Examples

fn foo() {
    let zero_u32 = u32::zero();
    assert(zero_u32.is_zero());
}

fn try_as_u8(self) -> Option<u8>

fn try_as_u16(self) -> Option<u16>

fn to_le_bytes(self) -> [u8; 4]

Converts the u32 to a sequence of little-endian bytes.

Returns

  • [[u8; 4]] - An array of 4 u8 bytes that compose the u32.

Examples

fn foo() {
    let x: u32 = 67305985;
    let result = x.to_le_bytes();

    assert(result[0] == 1_u8);
    assert(result[1] == 2_u8);
    assert(result[2] == 3_u8);
    assert(result[3] == 4_u8);
}

fn from_le_bytes(bytes: [u8; 4]) -> Self

Converts a sequence of little-endian bytes to a u32.

Arguments

  • bytes: [[u8; 4]] - A sequence of 4 u8 bytes that represent a u32.

Returns

  • [u32] - The resulting u32 value.

Examples

fn foo() {
    let bytes = [1_u8, 2_u8, 3_u8, 4_u8];
    let result = u32::from_le_bytes(bytes);

    assert(result == 67305985_u32);
}

fn to_be_bytes(self) -> [u8; 4]

Converts the u32 to a sequence of big-endian bytes.

Returns

  • [[u8; 4]] - An array of 4 u8 bytes that compose the u32.

Examples

fn foo() {
    let x: u32 = 67305985;
    let result = x.to_be_bytes();

    assert(result[0] == 4_u8);
    assert(result[1] == 3_u8);
    assert(result[2] == 2_u8);
    assert(result[3] == 1_u8);
}

fn from_be_bytes(bytes: [u8; 4]) -> Self

Converts a sequence of big-endian bytes to a u32.

Arguments

  • bytes: [[u8; 4]] - A sequence of 4 u8 bytes that represent a u32.

Returns

  • [u32] - The resulting u32 value.

Examples

fn foo() {
    let bytes = [4_u8, 3_u8, 2_u8, 1_u8];
    let result = u32::from_be_bytes(bytes);

    assert(result == 67305985_u32);
}

fn to_le_bytes(self) -> Bytes

Converts the u32 to a sequence of little-endian bytes.

Returns

  • [Bytes] - The 4 bytes that compose the u32.

Examples

use std::bytes_conversions::u32::*;

fn foo() {
    let x: u32 = 67305985;
    let result = x.to_le_bytes();

    assert(result.get(0).unwrap() == 1_u8);
    assert(result.get(1).unwrap() == 2_u8);
    assert(result.get(2).unwrap() == 3_u8);
    assert(result.get(3).unwrap() == 4_u8);
}

fn from_le_bytes(bytes: Bytes) -> Self

Converts a sequence of little-endian bytes to a u32.

Arguments

  • bytes: [Bytes] - The 4 bytes that compose the u32.

Returns

  • [u32] - The resulting u32 value.

Examples

use std::{bytes::Bytes, bytes_conversions::u32::*};

fn foo() {
    let mut bytes = Bytes::new();
    bytes.push(1_u8);
    bytes.push(2_u8);
    bytes.push(3_u8);
    bytes.push(4_u8);
    let result = u32::from_le_bytes(bytes);

    assert(result == 67305985_u32);
}

fn to_be_bytes(self) -> Bytes

Converts the u32 to a sequence of big-endian bytes.

Returns

  • [Bytes] - The 4 bytes that compose the u32.

Examples

use std::bytes_conversions::u32::*;

fn foo() {
    let x: u32 = 67305985;
    let result = x.to_be_bytes();

    assert(result.get(0).unwrap() == 4_u8);
    assert(result.get(1).unwrap() == 3_u8);
    assert(result.get(2).unwrap() == 2_u8);
    assert(result.get(3).unwrap() == 1_u8);
}

fn from_be_bytes(bytes: Bytes) -> Self

Converts a sequence of big-endian bytes to a u32.

Arguments

  • bytes: [Bytes] - The 4 bytes that compose the u32.

Returns

  • [u32] - The resulting u32 value.

Examples

use std::{bytes::Bytes, bytes_conversions::u32::*};

fn foo() {
    let mut bytes = Bytes::new();
    bytes.push(4_u8);
    bytes.push(3_u8);
    bytes.push(2_u8);
    bytes.push(1_u8);
    let result = u32::from_be_bytes(bytes);

    assert(result == 67305985_u32);
}

Trait Implementations

fn sqrt(self) -> Self

fn pow(self, exponent: u32) -> Self

fn log(self, base: Self) -> Self

fn log2(self) -> Self

fn from(u: u8) -> Self

Casts a u8 to a u32.

Returns

  • [u32] - The u32 representation of the u8 value.

Examples


fn foo() {
    let u32_value = u32::from(0u8);
}

fn from(u: u16) -> Self

Casts a u16 to a u32.

Returns

  • [u32] - The u32 representation of the u16 value.

Examples


fn foo() {
    let u32_value = u32::from(0u16);
}

fn try_from(u: u64) -> Option<Self>

fn try_from(u: u256) -> Option<Self>

fn try_from(u: U128) -> Option<Self>

fn hash(
self,
refmut state: Hasher,
)