Hi Walter. John Payson's example was shorter/faster :) Originally in asm, can be easily ported to c if required. rrf ch,W ;x = ch >> 1 xorwf ch,F ;ch ^= x swapf ch,W ;x = ch >> 4 | ch << 4 xorwf ch,F ;ch ^= x btfsc ch,2 ;if ( ch & 4 ) ch++ incf ch,F ; or incf ch,W if needed ;bit.0 has a parity WBR Dmitriy. PS. I've seen John's posts recently in htsoft forums. Walter Banks wrote: > > One of my favorite compromise parity checkers was > originally implemented in hardware and published > in electronics design. In the original the ac was declared as > an accumulator it can be replaced as a local variable. > > If you use this any public way credit the sources. > > It is a clever algorithm > > w.. > > int parity(char ch) > { > /* > Implemented in C Based on the original > hardware implementation in Electronics design. > Walter Banks Byte Craft Limited > September 1991 > > Electonics Design Aug 22, 1991 > Noor Singh Khalsa > EG&G > P.O Box 809, > MS E-1, Los Alamos, NM 87544 > (505) 667-0200 > */ > > ch = (ch >> 1) ^ ch ; > return (((ac = (((ch >> 2) ^ ch)) & 0x11) == 0) ? 1 : ((ac ^ 0x11) == 0) ); > if ((ch = (((ch >> 2) ^ ch)) & 0x11) == 0) return 1; > if ((ch ^ 0x11) == 0) return 1; > return 0; > } > > Brian Millward wrote: > > > I am fairly new to PIC programming and I am building a radio clock to decode > > Rugby MSF transmissions. > > > > > > > > It all works, but I have not done any parity checking. > > > > > > > > I have some BCD variables and a checksum bit and I need to check that all > > the bits add up to an odd number. > > > > > > > > I have thought of checking the lsb, then shifting right and repeating etc, > > adding all the bits together, but I am sure that there is an easier way I > > just cannot think of it > > > > > > > > Apologies for seeming to be a bit dense, but I am trying to master it. > > > > > > > > By the way, I am using CCS 'C' compiler. > > > > > > > > Thanks for any help you may be able to give. > > > > > > > > Regards ... Brian > > > > -- > > http://www.piclist.com PIC/SX FAQ & list archive > > View/change your membership options at > > http://mailman.mit.edu/mailman/listinfo/piclist > > -- > http://www.piclist.com PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist