Advertisement
Alx09

Untitled

May 31st, 2020
1,190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.36 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int f(int nr) {
  4.     int n = 0, i = 31, t = 0;
  5.     while ((nr >> i) == 0) i--;
  6.     while (i >= 0) {
  7.         n |= (((nr & (1 << i)) != 0 ) << t);
  8.         t++;
  9.         i--;
  10.     }
  11.     return n;
  12. }
  13. int main() {
  14.     int n;
  15.     printf("n= "); scanf("%d", &n);
  16.     printf("Numarul obtinuit prin oglindirea biitlor numarului %d este %d\n", n, f(n));
  17.     return 0;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement