Crackbone

dv5z4

Apr 18th, 2021
665
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*4. Napisati funkciju koja setira k-ti bit u broju n i funkciju koja provjerava je li k-ti bit
  2. setiran. Funkcija vraća novonastali broj.
  3. Primjer: Za broj n = 200 i k = 2, binarni zapis novonastalog broja je 11001100, što
  4. odgovara broju 204.*/
  5.  
  6. #define _CRT_SECURE_NO_WARNINGS
  7.  
  8. #include<stdio.h>
  9.  
  10. int dTb(int);
  11. void bit_set(int*, int);
  12.  
  13. int main()
  14. {
  15.     int number, bin_number,k;
  16.     printf("Unesi broj:\n");
  17.     scanf(" %d", &number);
  18.     printf("\n");
  19.     bin_number = dTb(number);
  20.     printf("Binarni broj je: %d", bin_number);
  21.     printf("\nKoji bit zelis setirati:\n");
  22.     scanf(" %d", &k);
  23.     bit_set(&number, k);
  24.     bin_number = dTb(number);
  25.     printf("\nBinarni broj je: %d", bin_number);
  26.     getchar();
  27.     getchar();
  28.     return 1;
  29. }
  30.  
  31. int dTb(int number)
  32. {
  33.     int bin_numb = 0, remain, temp = 1;
  34.     while (number > 0)
  35.     {
  36.         remain = number % 2;
  37.         number = number / 2;
  38.         bin_numb = bin_numb + remain * temp;
  39.         temp = temp * 10;
  40.  
  41.     }
  42.  
  43.  
  44.     return bin_numb;
  45. }
  46.  
  47. void bit_set(int *number, int k)
  48. {
  49.     *number |= 1 << k;
  50. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×