Last active
December 31, 2015 09:29
-
-
Save passcod/7966684 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| rot.rs:19:8: 19:9 error: mismatched types: expected `T` but found `int` (expected type parameter but found int) | |
| rot.rs:19 (x << n) | (x >> (bitsize - n)) | |
| ^ | |
| rot.rs:19:19: 19:33 error: mismatched types: expected `T` but found `int` (expected type parameter but found int) | |
| rot.rs:19 (x << n) | (x >> (bitsize - n)) | |
| ^~~~~~~~~~~~~~ | |
| error: aborting due to 2 previous errors |
This file contains hidden or 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 rot8(x: u8, n: int) -> u8 { | |
| (x << n) | (x >> (8 - n)) | |
| } | |
| fn rot16(x: u16, n: int) -> u16 { | |
| (x << n) | (x >> (16 - n)) | |
| } | |
| fn rot32(x: u32, n: int) -> u32 { | |
| (x << n) | (x >> (32 - n)) | |
| } | |
| fn rot64(x: u64, n: int) -> u64 { | |
| (x << n) | (x >> (64 - n)) | |
| } | |
| fn rot<T: std::num::Unsigned + std::num::Bitwise>(x: T, n: int) -> T { | |
| let bitsize: int = std::num::cast(std::sys::size_of_val(&x) * 8); | |
| (x << n) | (x >> (bitsize - n)) | |
| } | |
| fn main() { | |
| let n8: u8 = 314; | |
| let n16: u16 = 31415; | |
| let n32: u32 = 3141592; | |
| let n64: u64 = 314159265; | |
| let n: uint = 31415926535; | |
| println!(" 8: {:?} {:?}", n8, rot8(n8, 1)); | |
| println!("16: {:?} {:?}", n16, rot16(n16, -2)); | |
| println!("32: {:?} {:?}", n32, rot32(n32, 3)); | |
| println!("64: {:?} {:?}", n64, rot64(n64, -4)); | |
| println!("u*: {:?} {:?}", n, rot(n, 5)); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment