C practical exercises topic 54

Time:2020-7-30

Title:Take 4-7 bits from the right end of an integer a.

Program analysis:Consider this:

(1) First, shift a to the right by 4 bits.

(2) Set a number with all the lower 4 bits as 1 and all the others as 0. Use ~ (~ 0 < < 4)

(3) Perform the & operation on the above two.

example:

#include 
 int main()
 {
     unsigned a,b,c,d;
     Printf ("please enter integer (s):";
     scanf("%o",&a);
     b=a>>4;
     c=~(~0<<4);
     d=b&c;
     printf("%o\n%o\n",a,d);
     return 0;
 }

The output results of the above examples are as follows:

Please enter an integer:
36
36
1

Thank you for your reading, please feel with your heart! Hope to help you who love learning!! Sharing is also a kind of happiness!!! Please relay…

Click to view the original text, thank you!