想知道波浪算子
wanted to know about ~tilde operator?
本文关键字:想知道 更新时间:2023-10-16
我看过很多网站和参考书籍,并且达到了使用波浪(~)运算符进行1的补码的程度,但是当我运行下面的代码片段时,我对它的输出感到惊讶。有人能解释一下输出吗?
下面代码的输出是-11。如有任何帮助,不胜感激。
#include <iostream>
using namespace std;
int main() {
int x=10;
cout<<~x;
return 0;
}
波浪是位非操作符,所以它所做的是反转位。因为int是有符号的,所以它对负数使用2的补码:
00001010 = 10
11110101 = -11
这里所涉及的运算符是http://en.cppreference.com/w/cpp/language/operator_arithmetic按位非运算符,它将数字10的所有位进行反转,以得到数字-11,这是由位反转产生的。
相关文章:
- 我想知道长双倍和双倍之间的区别
- 我是 C++ 的初学者,我想知道如何在 2D 矢量中获取重复值
- C++新手,想知道如何使用VS code 2019播放音频文件
- 我是C++新手,我想知道,为什么在c ++中使用纯虚函数?为什么要使用纯虚函数?
- 我想知道为什么"std::unique_ptr<int> foo(新 int)"是合法的,因为"std::<int>unique_ptr"要求输入参数类型应该是"int"?
- 我想知道我是否可以将一个类分配给特定的成员数据并创建该类的实例
- 我想知道变焦和轨道在哪里出了问题
- 我创建了一个库,想知道设计是否效率低下
- 想知道我哪里错了
- 我想知道我将如何实现 + 运算符重载.我已经从我上一个问题中计算出 += 运算符重载
- 将VS2013 更新为VS2019会导致左值错误,想知道原因
- 我想知道如何将所有数值与没有任何空格的字符串分开,就像 123we45rt75 一样
- 我想知道在构造函数中初始化变量时的生命周期
- 我想知道像素/片段的原始模板值.零还是一个?如果可能的话,以获取哪些特定操作会修改模板值
- 在Visual Studio 2013中编译的STL列表代码在Visual Studio 2019中给出了错误.想知道原
- VS为我提供了对构造函数的另一个解决方案,但我想知道为什么我的工作不起作用
- 我想知道下面的指针等同于做什么
- 我想知道这个原因和解决方案
- 想知道为什么我不能只捕获协程的 asio::handler_type 的引用
- C STL,我想知道地图中的双向迭代器和操作员[]之间有什么不同