|
Last change
on this file since 117 was
102,
checked in by rosiere, 17 years ago
|
|
Previous commit with new files :P
|
-
Property svn:keywords set to
Id
|
|
File size:
711 bytes
|
| Line | |
|---|
| 1 | #include "func_parite.h" |
|---|
| 2 | |
|---|
| 3 | // Renvoye 1 si le nombre de bit a 1 est impaire |
|---|
| 4 | // 0 paire |
|---|
| 5 | |
|---|
| 6 | bool parite1(int x,int val_parite) |
|---|
| 7 | { |
|---|
| 8 | int mask = 1; |
|---|
| 9 | bool res = ( (val_parite & mask) ^ mask); //si bit de poids faible à zero alors parité pair |
|---|
| 10 | |
|---|
| 11 | while(x!=0) |
|---|
| 12 | { |
|---|
| 13 | res ^= (x & mask); |
|---|
| 14 | x = x >> 1; |
|---|
| 15 | } |
|---|
| 16 | |
|---|
| 17 | return res; |
|---|
| 18 | } |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | extern unsigned int find_first_one (int x); |
|---|
| 22 | |
|---|
| 23 | bool parite2(int x,int val_parite) |
|---|
| 24 | { |
|---|
| 25 | unsigned int mask = 1; |
|---|
| 26 | unsigned int pos; |
|---|
| 27 | bool res = ( (val_parite & mask) ^ mask); //si bit de poids faible à zero alors parité pair |
|---|
| 28 | |
|---|
| 29 | while ((pos = find_first_one(x)) != 0) |
|---|
| 30 | { |
|---|
| 31 | res ^= 1; |
|---|
| 32 | x = x >> pos; |
|---|
| 33 | } |
|---|
| 34 | |
|---|
| 35 | return res; |
|---|
| 36 | } |
|---|
Note: See
TracBrowser
for help on using the repository browser.