Merge pull request #1383 from tianq02/patch-1

修改位操作示例展示效果
pull/1465/head
Sunface 3 months ago committed by GitHub
commit e5dfe14842
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -258,27 +258,33 @@ Rust 的位运算基本上和其他语言一样
```rust
fn main() {
// 二进制为00000010
let a:i32 = 2;
// 无符号8位整数二进制为00000010
let a: u8 = 2; // 也可以写 let a: u8 = 0b_0000_0010;
// 二进制为00000011
let b:i32 = 3;
let b: u8 = 3;
// {:08b}左高右低输出二进制01不足8位则高位补0
println!("a value is {:08b}", a);
println!("b value is {:08b}", b);
println!("(a & b) value is {}", a & b);
println!("(a & b) value is {:08b}", a & b);
println!("(a | b) value is {}", a | b);
println!("(a | b) value is {:08b}", a | b);
println!("(a ^ b) value is {}", a ^ b);
println!("(a ^ b) value is {:08b}", a ^ b);
println!("(!b) value is {} ", !b);
println!("(!b) value is {:08b}", !b);
println!("(a << b) value is {}", a << b);
println!("(a << b) value is {:08b}", a << b);
println!("(a >> b) value is {}", a >> b);
println!("(a >> b) value is {:08b}", a >> b);
let mut a = a;
// 注意这些计算符除了!之外都可以加上=进行赋值 (因为!=要用来判断不等于)
a <<= b;
println!("(a << b) value is {}", a);
println!("(a << b) value is {:08b}", a);
}
```

Loading…
Cancel
Save