Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

Re: [AVR-Chat] Exclusive or

2004-06-20 by wagner

David VanHorn wrote:
> What's the fastest way to get the exclusive or, of four bits in a
> register?
>
> 0000 = 0
> 0001 = 1
> 0010 = 1
> 0011 = 0
> 0100 = 1
> 0101 = 0
> 0110 = 0
> 0111 = 0
>  and so on...
>
> Not for a parity generator, but I think it ends up as the same
> problem.


That is a very tricky question.

If you assume literaly "Exclusive Or" for 4 bits, you are stating that when
JUST ONE bit is UP you will have output UP, it means, only the following
combinations will have output UP:

0001
0010
0100
1000

I can think of many fancy ways to verify that, including digital external
and even a jaw dropping 5 resistors tied to 4 output pins to read an analog
voltage via an adc to identify just one output pin up, but not so simply as
4 easy comparisons for 1, 2, 4 and 8.  This could be done in few different
ways, a loop with a binary shifting 4 comparisons, pure 4 comparisons with
fixed values, etc.

Wagner


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.706 / Virus Database: 462 - Release Date: 6/14/2004

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.