简体   繁体   中英

questions about operator “&”

Probably have wrong title,but I don't know how to describe it.

int x=0x4a;
h=!(0x80000000000&(0x39+(~x+1)));

the result is h=0. The question is x has 32 bits, while 0x80000000000 has more than 32 bit. If I set variable i to 0x80000000000 and print it as hex format,it will show 0. So in that case, why not the result of h is 1 because 0x80000000000 turns to be 0?

The language I used is C

0x8000000000 is a long long int constant. Therefore the C compiler promotes the types in an arithmetic expression to the highest precision that occurs within an expression.

If instead you wrote:

  int x=0x4a;
  int h1=(0x80000000000&(0x39+(~x+1)));
  int h = !h1;

Then h would become 1. And perhaps a warning on missing precision would be issued.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM