Skip to content

Instantly share code, notes, and snippets.

View Andrew-Shay's full-sized avatar

Andrew Shay Andrew-Shay

View GitHub Profile
@Andrew-Shay
Andrew-Shay / rust_convert_u32_to_bytes.rs
Created May 25, 2020 23:09
Rust: Convert u32 to bytes. Convert bytes to u32.
fn main() {
let original_u32: u32 = 1048572;
println!("{}", original_u32);
let u32_as_bytes: [u8; 4] = original_u32.to_be_bytes();
println!("{:?}", u32_as_bytes);
let back_to_u32: u32 = u32::from_be_bytes(u32_as_bytes);
println!("{}", back_to_u32);
}