Rust中按位NOT运算符是什么? [英] What is the bitwise NOT operator in Rust?

查看:287
本文介绍了Rust中按位NOT运算符是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

查看按位运算符列表,我没有看到NOT运算符(如C中的~). Rust中没有NOT运算符吗?

Looking at the list of bitwise operators in the Rust Book, I don't see a NOT operator (like ~ in C). Is there no NOT operator in Rust?

推荐答案

游乐场):

The ! operator is implemented for many primitive types and it's equivalent to the ~ operator in C. See this example (playground):

let x = 0b10101010u8;
let y = !x;
println!("x: {:0>8b}", x);
println!("y: {:0>8b}", y);

输出:

x: 10101010
y: 01010101

另请参阅:

这篇关于Rust中按位NOT运算符是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆