Home > Back-end >  C language for beginners, bosses give directions
C language for beginners, bosses give directions

Time:10-09

CodePudding user response:

For example
 int main (int arg c, const char * argv []) {
Int x, p, n.
The scanf (" % d ", & amp; X);
The scanf (" % d % d ", & amp; P, & amp; N);
Int v1=(x> (32 - p - 1)) & lt; <(32 - p - 1);//p of the left side (moves to the right and left, the right side of the qing 0) p
Int v2=(1 & lt; V2=x % v2;//here more than using the method of simplified (can also shift)
Int the v3=0;//p - part n
For (int I=0; i<=p - n; I++) {//take out the number of bits to n and p in the
V3=((~ ((x> (p - I)) & amp; 0 x00000001)) & amp; 0 x00000001) & lt; <(p - I) | v3;
}
Printf (" % d \ n ", v1 | v3 | v2);
return 0;
}

CodePudding user response:

reference 1st floor qybao response:
for example
 int main (int arg c, const char * argv []) {
Int x, p, n.
The scanf (" % d ", & amp; X);
The scanf (" % d % d ", & amp; P, & amp; N);
Int v1=(x> (32 - p - 1)) & lt; <(32 - p - 1);//p of the left side (moves to the right and left, the right side of the qing 0) p
Int v2=(1 & lt; V2=x % v2;//here more than using the method of simplified (can also shift)
Int the v3=0;//p - part n
For (int I=0; i<=p - n; I++) {//take out the number of bits to n and p in the
V3=((~ ((x> (p - I)) & amp; 0 x00000001)) & amp; 0 x00000001) & lt; <(p - I) | v3;
}
Printf (" % d \ n ", v1 | v3 | v2);
return 0;
}

For using an expression that if only the

CodePudding user response:

Then you can put the v1, v2, v3 together to write, the separate written imagine let you clear logic
Int v=(x/(1 & lt; <| (p + 1))) (x % (1 & lt; <(n)) | ~ (x % 1 & lt; <(p + 1) - (x % 1 & lt; Printf (" % d \ n ", v);

CodePudding user response:

Change
Int v=(x (x % (1 & lt; <(p + 1)))) | (x % (1 & lt; <(n)) | ~ (x % 1 & lt; <(p + 1) - (x % 1 & lt; CodePudding user response:

Subtraction can use & amp; Reduction of the
Int v=(x & amp; ~ (x % (1 & lt; <(p + 1)))) | (x % (1 & lt; <(n)) | ~ (x % 1 & lt; <(p + 1)) & amp; ~ (x % (1 & lt;

CodePudding user response:

reference 5 floor qybao reply:
subtraction can use & amp; Reduction of the
Int v=(x & amp; ~ (x % (1 & lt; <(p + 1)))) | (x % (1 & lt; <(n)) | ~ (x % 1 & lt; <(p + 1)) & amp; ~ (x % (1 & lt;

If does not conform to the question, however,

CodePudding user response:

refer to 6th floor milk____shake response:
but, as if does not conform to the question of

Ignore the middle part of the not turned negative, to fix back
Int v=(x & amp; ~ (x % (1 & lt; <(p + 1)))) | (x % (1 & lt; <(n)) | (~ (x % 1 & lt; <(p + 1)) & amp; ~ (x % (1 & lt; P));
Or intermediate variable
Int m=(0 x7fffffff & lt; P);
Int v=(x & amp; ~ (x % (1 & lt; <(p + 1)))) | (x % (1 & lt; <(n)) | (~ (x % 1 & lt; <(p + 1)) & amp; ~ (x % (1 & lt; CodePudding user response:

So that more convenient
Int m=(0 x7fffffff & lt; P);//p - n parts is 1, the rest are 0
Int v=~ (x & amp; M) & amp; (x | m);
  • Related