
二进制数以基数 2 表示。它仅使用“0”和“1”两位数字。二进制数中的每个数字都是一个位。
示例二进制数 - 0100010111
二进制的补码number 是通过将二进制数的数字反转,即 1 转为 0,0 转为 1 得到的。
1’s Complement of 101100 = 010011
二进制数的补码是二进制数的补码加 1,即 1 的补码 + 1。
2’s complement of 101101 is 010011.
查找一个和两个补码的代码 -
#include <iostream>
#include<string.h>
using namespace std;
int main() {
char binary[10] = "01001011";
cout<<“Binary number is ”<<binary;
//once complement....
int length = strlen(binary);
for(int i=0;i<length;i++) {
if(binary[i] == '0') {
binary[i]= '1';
} else
binary[i] = '0';
}
cout<<“One’s Complement is ”<<binary<<endl;
// cout<<binary[length-1];
for(int i = length-1; i>=0; i--) {
// cout<<binary[i];
if(binary[i] == '0') {
binary[i] = '1';
//cout<<binary[i];
break;
} else {
binary[i] = '0';
}
}
cout<<“Two’s complement is ”<<binary;
return 0;
}Binary number is 01001011 One’s complement is 10110100 Two’s complement is 10110101
以上就是二进制数的1的补码和2的补码是什么?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号