Keil™, An ARM® Company

Technical Support

C251: OBTAINING THE PARITY OF A CHARACTER


Information in this article applies to:

  • C251 Version 1.24 and higher
  • C51 Version 5.50a and higher

QUESTION

Is there a convenient way to obtain the parity of a char value? In assembly language, I can examine the parity bit in the PSW just after loading it into the Accumulator. Is this possible in C51 and C251, too?

ANSWER

Yes. You may use the ACC SFR to access the accumulator in the C language. The following example shows how to get the parity of a character:

#include <reg51.h>  // use the header file for the CPU that you are using

// variant 1:  global variables
unsigned char c;
bit parity;

void get_parity (void)  {
  ACC = c;                          // you may use this code within your function
  parity = P;
}


// variant 2:  a deticated function to get the parity bit.
bit get_parity2 (unsigned char uc)  {
  ACC = uc;
  return (P);
}

Last Reviewed: Tuesday, June 20, 2000


Did this article provide the answer you needed?
 
Yes
No
Not Sure