Keil Logo

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
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.