Skip to content

Instantly share code, notes, and snippets.

@dbp
Created August 16, 2012 16:39
Show Gist options
  • Save dbp/3371538 to your computer and use it in GitHub Desktop.
Save dbp/3371538 to your computer and use it in GitHub Desktop.
converting ~[u8] to u32
fn main() {
let bytes : ~[u8] = ~[1,1,1]; // for example
let len = vec::len(bytes)-1;
let mut out: u32 = 0;
do vec::iteri(bytes) |i, b| {
out += (b as u32) << (8*(len-i))
}
io::println(u32::str(out));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment