subdural
Junior Member level 1
- Joined
- Aug 21, 2004
- Messages
- 19
- Helped
- 1
- Reputation
- 2
- Reaction score
- 0
- Trophy points
- 1,281
- Location
- Neutral Zone
- Activity points
- 173
parity calculation
Hi!
I'm newbie. I have the main.c source code as below. I'd to know how to program source the parity of 32 bit word calculation then determine whether the number is even (parity is zero) or the number is odd (parity is 1) in C language. Says that the parity program is difference source code called parity.c source code.Thanks
main.c source code
----------------------
main()
{ int attempt, in, out;
attempt = 1;
while (attempt < 7) {
printf("Enter a 32-bit value in hex:");
scanf("%X", &in);
if(parity(in))
printf("Value %X has odd parity\n", in);
else
printf("Value %X has even parity\n", in);
attempt++;
}
}
-------------------------------------------------------------------
after compile
$ gcc main.c parity.s -o test.exe
Expected results after gcc run as below
$ gcc run test.exe
Enter a 32-bit value in hex: ffffffff
Value ffffffff has even parity
Enter a 32-bit value in hex: fffffffe
Value fffffffe has odd parity
Enter a 32-bit value in hex: 0
Value 00000000 has even parity
Enter a 32-bit value in hex: 1
Value 00000001 has odd parity
Enter a 32-bit value in hex: ffff0000
Value ffff0000 has even parity
Enter a 32-bit value in hex: 55554555
Value 55554555 has odd parity
Enter a 32-bit value in hex: 12345678
Value 12345678 has odd parity
Hi!
I'm newbie. I have the main.c source code as below. I'd to know how to program source the parity of 32 bit word calculation then determine whether the number is even (parity is zero) or the number is odd (parity is 1) in C language. Says that the parity program is difference source code called parity.c source code.Thanks
main.c source code
----------------------
main()
{ int attempt, in, out;
attempt = 1;
while (attempt < 7) {
printf("Enter a 32-bit value in hex:");
scanf("%X", &in);
if(parity(in))
printf("Value %X has odd parity\n", in);
else
printf("Value %X has even parity\n", in);
attempt++;
}
}
-------------------------------------------------------------------
after compile
$ gcc main.c parity.s -o test.exe
Expected results after gcc run as below
$ gcc run test.exe
Enter a 32-bit value in hex: ffffffff
Value ffffffff has even parity
Enter a 32-bit value in hex: fffffffe
Value fffffffe has odd parity
Enter a 32-bit value in hex: 0
Value 00000000 has even parity
Enter a 32-bit value in hex: 1
Value 00000001 has odd parity
Enter a 32-bit value in hex: ffff0000
Value ffff0000 has even parity
Enter a 32-bit value in hex: 55554555
Value 55554555 has odd parity
Enter a 32-bit value in hex: 12345678
Value 12345678 has odd parity