Advertisement
NPantev

Untitled

Jun 26th, 2022
678
130 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.66 KB | None
  1. /*
  2. 10) Премахнете всички битове на число след n-тия
  3. бит включително.
  4. */
  5.  
  6. #include <stdio.h>
  7.  
  8.  
  9. int main()
  10. {
  11.     int number, index, i;
  12.     int result;
  13.    
  14.     printf("Enter number:\n"); // 18 => 00010010
  15.     scanf("%d", &number);
  16.     result = number;
  17.  
  18.     printf("----------\n");
  19.  
  20.     printf("Enter from which index you would like to cut the bits:\n"); // 3
  21.     scanf("%d", &index);
  22.  
  23.     printf("----------\n");
  24.  
  25.    
  26.     for ( i = index; i < 9; i++)
  27.     {
  28.         result = result & ~(1<<i);
  29.     }
  30.    
  31.  
  32.    
  33.     printf("The result is = %d", result); // 2 => 00000010
  34.  
  35.  
  36.     return 0;
  37.  
  38.    
  39. }
Advertisement
RAW Paste Data Copied
Advertisement