【问题标题】:What is the bitwise NOT operator in Rust?Rust 中的按位 NOT 运算符是什么?
【发布时间】:2016-08-11 12:16:20
【问题描述】:

查看list of bitwise operators in the Rust Book,我没有看到NOT 运算符(如C 中的~)。 Rust 中没有 NOT 运算符吗?

【问题讨论】:

    标签: rust operators


    【解决方案1】:

    ! operator 是为许多基本类型实现的,它等效于 C 中的 ~ 运算符。请参阅此示例 (playground):

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

    输出:

    x: 10101010
    y: 01010101
    

    另见:

    【讨论】:

    猜你喜欢
    • 2014-12-24
    • 2019-01-05
    • 2011-07-21
    • 1970-01-01
    • 1970-01-01
    • 2010-09-21
    相关资源
    最近更新 更多