当前位置:网站首页>按位逻辑运算符
按位逻辑运算符
2022-07-06 08:22:00 【踏破铁鞋无觅处,bug一写一上午】
一、按位取反:~
在计算机中,数据都是按照二进制进行存储的,即便有了原码、反码、补码。而二进制数在内存中是以补码的形式存储的。
按位取反是将补码的每一位都取反,即0变1,1变0;
#include <stdio.h>
int main()
{
char a = 5;
printf("%d", ~a);
return 0;
}
结果为-6;
正整数:5
正数的原码、反码、补码相同:00000101
按位取反:11111010 //此时取反的结果为原码,还需要将其转化为补码
反码:10000101
补码:10000110
结果:-6
负整数:-5
原码:10000101
反码:11111010
补码:11111011
按位取反:00000100 //此时取反的结果为原码,因为原码为正数,原反补相同
结果:4
正数按位取反等于其本身+1的负数
负数按位取反等于其本身+1的正数
0按位取反为-1
二、按位与:&
[规则]
0&0=0
0&1=0
1&0=0
1&1=1
#include <stdio.h>
int main()
{
char a = 5,b=9;
char c = a&b;
printf("%d", c);
return 0;
}
结果为1
5的补码:00000101
9的补码:00001001
按位与后结果:00000001 //此时的结果为原码,因为原码为正数,原反补相同
结果:1
三、按位或:|
[规则]
0|0=0
0|1=1
1|0=1
1|1=1
#include <stdio.h>
int main()
{
char a = 5,b=9;
char c = a|b;
printf("%d", c);
return 0;
}
结果为13
5的补码:00000101
9的补码:00001001
按位或后结果:00001101 //此时的结果为原码,因为原码为正数,原反补相同
结果:13
四、按位异或:^
[规则]
0^0=0
0^1=1
1^0=1
1^1=0
#include <stdio.h>
int main()
{
char a = 5,b=9;
char c = a^b;
printf("%d", c);
return 0;
}
结果为12
5的补码:00000101
9的补码:00001001
按位与或后结果:00001100 //此时的结果为原码,因为原码为正数,原反补相同
结果:12
边栏推荐
- 1202 character lookup
- Make learning pointer easier (3)
- Migrate data from a tidb cluster to another tidb cluster
- Nft智能合约发行,盲盒,公开发售技术实战--合约篇
- Char to leading 0
- Research Report on supply and demand and development prospects of China's high purity aluminum market (2022 Edition)
- 延迟初始化和密封类
- 灰度升级 TiDB Operator
- [cloud native] teach you how to build ferry open source work order system
- tree树的精准查询
猜你喜欢

根据csv文件某一列字符串中某个数字排序

C语言自定义类型:结构体
![[MySQL] lock](/img/ce/9f8089da60d9b3a3f92a5e4eebfc13.png)
[MySQL] lock

Asia Pacific Financial Media | female pattern ladyvision: forced the hotel to upgrade security. The drunk woman died in the guest room, and the hotel was sentenced not to pay compensation | APEC secur

Easy to use tcp-udp_ Debug tool download and use

Configuring OSPF load sharing for Huawei devices

Let the bullets fly for a while

Online yaml to CSV tool

MySQL learning records 12jdbc operation transactions

2022.02.13 - 238. Maximum number of "balloons"
随机推荐
pcd转ply后在meshlab无法打开,提示 Error details: Unespected eof
Char to leading 0
[2022 广东省赛M] 拉格朗日插值 (多元函数极值 分治NTT)
Huawei cloud OBS file upload and download tool class
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
How to use information mechanism to realize process mutual exclusion, process synchronization and precursor relationship
Configuring OSPF load sharing for Huawei devices
Yyds dry goods inventory three JS source code interpretation eventdispatcher
Résumé des diagrammes de description des broches de la série ESP
leetcode刷题 (5.29) 哈希表
Tidb backup and recovery introduction
C语言自定义类型:结构体
Upgrade tidb with tiup
面向个性化需求的在线云数据库混合调优系统 | SIGMOD 2022入选论文解读
使用 TiDB Lightning 恢复 S3 兼容存储上的备份数据
【MySQL】锁
What is the use of entering the critical point? How to realize STM32 single chip microcomputer?
Leetcode question brushing (5.28) hash table
MySQL learning record 11jdbcstatement object, SQL injection problem and Preparedstatement object
Upgrade tidb operator