按位运算产生意外输出

时间:2015-07-27 20:17:15

标签: c bitwise-operators bitwise-and

#include<stdio.h>
int main(void)
{
    int a=0x11;
    printf("\n %d",a);
    int b=10;
    int c=(a&b);
    printf("\t %d",c);
    return 0;
}

该计划的o / p是

  

17 0

但我希望程序能够对位进行操作,以便产生

  

17 16

为什么输出为0?

2 个答案:

答案 0 :(得分:5)

在您的情况下,sd-xx~ # mkdir /opt/ sd-xx~ # mkdir /opt/bin sd-xx~ # curl -L https://github.com/docker/compose/releases/download/1.3.3/docker-compose-`uname -s`-`uname -m` > /opt/bin/docker-compose % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 403 0 403 0 0 1076 0 --:--:-- --:--:-- --:--:-- 1080 100 7990k 100 7990k 0 0 2137k 0 0:00:03 0:00:03 --:--:-- 3176k sd-xx~ # chmod +x /opt/bin/docker-compose sd-xx~ # docker-compose Define and run multi-container applications with Docker. Usage: docker-compose [options] [COMMAND] [ARGS...] docker-compose -h|--help Options: -f, --file FILE Specify an alternate compose file (default: docker-compose.yml) -p, --project-name NAME Specify an alternate project name (default: directory name) --verbose Show more output -v, --version Print version and exit Commands: build Build or rebuild services help Get help on a command kill Kill containers logs View output from containers port Print the public port for a port binding ps List containers pull Pulls service images restart Restart services rm Remove stopped containers run Run a one-off command scale Set number of containers for a service start Start services stop Stop services up Create and start containers migrate-to-labels Recreate containers to add labels 的小数值为10,而不是十六进制 10.更改

b

 int b=10;

答案 1 :(得分:4)

二进制表示法0x11

0001 0001

10

0000 1010

您可以很容易地看到,这些值没有共同的1位。因此,这些值之间的按位和运算结果为0。你为什么期望它产生16