C语言里的与(&)或(|)非(~)异或(^)和移位运算符(<<,>>)

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int and1=7;
    int and2=1;
    int or1=7;
    int or2=1;
    int not=7;
    int xor1=7;
    int xor2=1;

    int andresult=and1&and2;
    int orresult=or1&or2;
    int notresutl=~not;
    int xorresult=xor1^xor2;

    printf("andresult %d\n",andresult);
    printf("orresult %d\n",orresult);
    printf("notresutl %d\n",notresutl);
    printf("xorresult %d\n",xorresult);


    int andresult2=andresult<<2;
    int notresutl2=notresutl>>2;


    printf("andresult2 %d\n",andresult2);
    printf("notresutl2 %d\n",notresutl2);

    return 0;
}

结果:

andresult 1
orresult 1
notresutl -8
xorresult 6
andresult2 4
notresutl2 -2

Process returned 0 (0x0)   execution time : 0.156 s
Press any key to continue.

C里的与或非异或运算和java里的相同,C中没有直接输出二进制的函数或者通配符,
移位运算符: >>右移<<左移
右移一位,除以2,
左移一位,乘以2;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值