std-method

Integer native-endian bytes

Round-trip bytes using the target architecture's byte order. Avoid native order for data shared between different architectures. Expected stdout (not executed): 500 Common mistake: Native byte order is not a portable file format.

Formal Syntax & Structure

rust syntaxrust
x.to_ne_bytes(); u32::from_ne_bytes(bytes)

Working Example

Example Snippetrust
fn main() {    let x = 500_u32;    println!("{}", u32::from_ne_bytes(x.to_ne_bytes()));}
Rust Reference