Advertisement
lukicdarkoo

Neparni paritet

Jan 6th, 2014
62
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.  
  3. short getBit(short value, short position) {
  4.     return ((1 << position) & value) >> position;
  5. }
  6.  
  7. int main() {
  8.     short value = 128;
  9.  
  10.     int ones = 0;
  11.  
  12.     int i = 0;
  13.     for (; i < 7; i++)
  14.         ones += getBit(value, i);
  15.  
  16.     //neparni paritet
  17.     if (ones % 2 != getBit(value, 7))
  18.         printf("Podatak je ispravan");
  19.     else printf("Podatak nije ispravan");
  20.  
  21.     return 0;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement