Home > Back-end >  The c language
The c language

Time:10-10

~ (~ 0 & lt; <32) why is equal to zero

CodePudding user response:

You can see for loop to print change
for (int i=0; i<33. I++) {
Printf (" % 08 x \ n ", ~ 0 & lt; Printf (" % 08 x \ n ", 1 & lt; }
Is ~ 0=0 XFFFFFFFF, left 32, is equivalent to an int digits of a loop, back to the origin of
So pretty ~ (~ 0), so is 0

CodePudding user response:

reference 1st floor qybao response:

you can cycle to print to see changefor (int i=0; i<33. I++) {
Printf (" % 08 x \ n ", ~ 0 & lt; Printf (" % 08 x \ n ", 1 & lt; }
Is ~ 0=0 XFFFFFFFF, left 32, is equivalent to an int digits of a loop, back to the origin of
So pretty ~ (~ 0), so still 0


Not
The priority of ~ above & lt;
To perform after ~ & lt;
0 is int type according to the literal understanding, as a 32 bit to explain it
~ 0 0 XFFFFFFFF
On the left side of the mobile 32 result is 0
Finally outside ~ will result into 0 XFFFFFFFF brackets
How do you explain?

CodePudding user response:

This is the right answer

For x & lt; To two kinds of circumstances, to distinguish the literal expression and
If it is literal, then y is greater than or equal to 32, is 0 ( this is a compiler, the compiler is smart enough to just go
Whether it's 1 & lt; <32 or 0 XFFFFFFFF & lt; <32 is 0
You can go to a test!


If the operation, so the first y of 32 modulus, then carries on the mobile computing
So the code execution process of the original poster is
1: ~ (~ 0 & lt; <32)
2: ~ (0 XFFFFFFFF & lt; <32)
3: ~ (0 XFFFFFFFF & lt; <0)
4: ~ 0 XFFFFFFFF
5:0

this is the problem that some interviewers often test!
That you will find that he had a number directly move left 32 times, and 32, a move the result of a completely different

You can write code 1 & lt; <33, but this is where the literal, direct is 0 ( some compilers may be different
If the int v=1; V<33
Ha, this interesting, it is equivalent to v<1; 2 don't 2

CodePudding user response:

Fun
reference 3 floor response:
this is the right answer

For x & lt; To two kinds of circumstances, to distinguish the literal expression and
If it is literal, then y is greater than or equal to 32, is 0 ( this is a compiler, the compiler is smart enough to just go
Whether it's 1 & lt; <32 or 0 XFFFFFFFF & lt; <32 is 0
You can go to a test!


If the operation, so the first y of 32 modulus, then carries on the mobile computing
So the code execution process of the original poster is
1: ~ (~ 0 & lt; <32)
2: ~ (0 XFFFFFFFF & lt; <32)
3: ~ (0 XFFFFFFFF & lt; <0)
4: ~ 0 XFFFFFFFF
5:0

this is the problem that some interviewers often test!
That you will find that he had a number directly move left 32 times, and 32, a move the result of a completely different

You can write code 1 & lt; <33, but this is where the literal, direct is 0 ( some compilers may be different
If the int v=1; V<33
Ha, this interesting, it is equivalent to v<1; Two not two

Didn't understand the code execution process step 2-3

CodePudding user response:

Ho ho, so that's why
Which means a shift any expression (whether in the left or right) of the shift operator, would be the displacement of the first digit of 32 modulus, modulus is the result of the ultimate displacement of digits

So the change in step 2, maybe LZ can understand
1: ~ (~ 0 & lt; <32)
2: ~ (~ 0 & lt; <32) (32%)
3: ~ (0 XFFFFFFFF & lt; <0)
3: ~ (0 XFFFFFFFF & lt; <0)
4: ~ 0 XFFFFFFFF
5:0

CodePudding user response:

reference 5 floor qybao reply:
ho ho, I see
Which means a shift any expression (whether in the left or right) of the shift operator, would be the displacement of the first digit of 32 modulus, modulus is the result of the ultimate displacement of digits

So the change in step 2, maybe LZ can understand
1: ~ (~ 0 & lt; <32)
2: ~ (~ 0 & lt; <32) (32%)
3: ~ (0 XFFFFFFFF & lt; <0)
3: ~ (0 XFFFFFFFF & lt; <0)
4: ~ 0 XFFFFFFFF
5:0

Oh oh, so that we can understand the
  • Related