Created
September 19, 2016 23:32
-
-
Save davidnuon/f3023b2c12056028a2f02e49ab660555 to your computer and use it in GitHub Desktop.
Handling overflows in rust
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
use std::num::Wrapping; | |
fn main() { | |
let a: u8 = 0xFF; | |
// a an unsigned 8-bit integer 0xFF | |
// 0xFF + 0x01 = 0x00 (Overflow) | |
println!("{}", (Wrapping(a) + Wrapping(0x01)).0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment