How to extract specific bits from a number in C?

后端 未结 8 1364
遥遥无期
遥遥无期 2020-12-08 07:35

I need to extract specific part (no of bits) of a short data type in C.

For Example I have a binary of 52504 as 11001101000 11000 and I want First 6 (

8条回答
  •  情深已故
    2020-12-08 08:19

    void  f(short int last, short int first, short int myNr){
          //construct mask for last bits
          short int mask=0;
          for(int i=0;i>1;} 
          aux=myNr;  
          aux&=mask;
          aux>>last; // only first bits are left and shifted
    }
    

    you can add parameters to get the values out or something

提交回复
热议问题