retepsnikrep
Senior Member
Lets assume I have a value which can be loaded into a variable b0 for instance.
How can I work out if it has an odd or even number of bits?
I need to work this out as I'm experimenting with AUSART transmission and need an even parity bit for my particular project.
I'll be using the 9th bit transmisison mode in the 18X AUSART to send a parity bit and the data manualy with pokes etc.
I'm using my Eeprom to store my data to be transmitted which can change and don't really want to use a lookup table unless I really have too.
I would prefer a routine which can determine if the byte has an even/odd number of bits.
Hippy I', grateful for your earlier idea but want to avoid going to the 28X1 or 2 to keep cost down a bit and make the board smaller.
I suppose just use the bit command to step throught the byte and add up the number of bits set to 1.
Then use if then to say
if number of bits set to 1 = 1,3,5,7 then odd
if number of bits set to 1 = 0,2,4,6,8 then even
Set my bit 9 parity bit then accordingly
Sound right?
Ideas?
How can I work out if it has an odd or even number of bits?
I need to work this out as I'm experimenting with AUSART transmission and need an even parity bit for my particular project.
I'll be using the 9th bit transmisison mode in the 18X AUSART to send a parity bit and the data manualy with pokes etc.
I'm using my Eeprom to store my data to be transmitted which can change and don't really want to use a lookup table unless I really have too.
I would prefer a routine which can determine if the byte has an even/odd number of bits.
Hippy I', grateful for your earlier idea but want to avoid going to the 28X1 or 2 to keep cost down a bit and make the board smaller.
I suppose just use the bit command to step throught the byte and add up the number of bits set to 1.
Then use if then to say
if number of bits set to 1 = 1,3,5,7 then odd
if number of bits set to 1 = 0,2,4,6,8 then even
Set my bit 9 parity bit then accordingly
Sound right?
Ideas?
Last edited: