Skip to content

Instantly share code, notes, and snippets.

@davidnuon
Created September 19, 2016 23:32
Show Gist options
  • Save davidnuon/f3023b2c12056028a2f02e49ab660555 to your computer and use it in GitHub Desktop.
Save davidnuon/f3023b2c12056028a2f02e49ab660555 to your computer and use it in GitHub Desktop.
Handling overflows in rust
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