March 2014 update
This commit is contained in:
parent
09687c4926
commit
a25938f123
1846 changed files with 21876 additions and 5203 deletions
19
Task/Gray-code/Rust/gray-code.rust
Normal file
19
Task/Gray-code/Rust/gray-code.rust
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
fn gray_encode(integer: uint) -> uint {
|
||||
(integer >> 1) ^ integer
|
||||
}
|
||||
|
||||
fn gray_decode(integer: uint) -> uint {
|
||||
match integer {
|
||||
0 => 0,
|
||||
_ => integer ^ gray_decode(integer >> 1)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fn main() {
|
||||
for i in range(0u,32u) {
|
||||
println!("{:2} {:0>5t} {:0>5t} {:2}", i, i, gray_encode(i),
|
||||
gray_decode(i));
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue