Advertisement
Guest User

Untitled

a guest
Jan 8th, 2020
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.42 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. unsigned int getbits(unsigned int x, int p, int n) {
  5.     return (x >> (p + 1 - n)) & ~(~0 << n);
  6. }
  7.  
  8. int main( int argc, char** argv ) {
  9.     unsigned int N, x;
  10.    
  11.     printf( "Inserisci numero:\t" );
  12.     scanf( "%d", &x );
  13.    
  14.     printf( "Ti calcolero' %d mod 2^N, inserisci N:\t", x );
  15.     scanf( "%d", &N );
  16.    
  17.     printf( "%d %% 2^%d = %d \n", x, N, getbits( x, N-1, N ) );
  18.    
  19.     return 0;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement