C
c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <stdio.h>
/*This program get a number fron 0 to 127 and convert it to binary code + parity bit to send by a 7E1 UART
*/
int parity;
unsigned char parityBit;
int showbits(unsigned char x){
char i=0;
parity=0;
for (i=7; i >= 0; i--){
putchar(x & (1u << i) ? '1':'0');
parity+=putchar(x & (1u << i) ? 1 : 0);
}
printf("\n");
printf("Counts of bits=%d\n",parity);
return parity;
}
int parityCheck() {
parityBit=((parity+1)%2==0)? 1: 0;
printf("%d is",parity);
printf((parityBit>0)?" odd\n":" even\n");
printf("Parity Bit=%d\n",parityBit);
return parityBit;
}
int main() {
unsigned int byte;
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run