Created
August 16, 2012 16:39
-
-
Save dbp/3371538 to your computer and use it in GitHub Desktop.
converting ~[u8] to u32
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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