[ back to toc ]

Hexadecimal parity

Date: 2002/05/12 19:26

Q:
Hello.
How do I set/clear the MSB of a hexadecimal value in order to give it even
parity.
Thanks.
A:
You actually do not want to do it to a hexadecimal value. It is only
hexadecimal when you read it from textual representation or when you print
it out. In all other cases this is just binary value in the memory of the
computer.

You have a variable:

unsigned long z;

and you want to clear/set the highest bit.

Declare two other variables

unsigned long zset,zclr;

then set their value:

zset = ~((~0) >> 1);
zclr = (~0) >> 1;

To clear the MSB bit

z &= zclr;

to set the MSB

z |= zset;

regards,
Peter

[ back to toc ]