ARM Technical Support Knowledge Articles

OBTAINING THE PARITY OF A CHARACTER

Applies to: C251 C Compiler

Answer


Information in this article applies to:


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);
}

Article last edited on: 2000-06-20 00:00:00

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential