Parity calculation
Ken Peterson
Posts: 806
Anybody know of a really efficient parity bit calculation routine in SPIN?· I have an application that needs ODD parity and I was wondering if there is a more elegant way than shifting and XORing.
Thankyou!·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The more I know, the more I know I don't know.· Is this what they call Wisdom?
Thankyou!·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The more I know, the more I know I don't know.· Is this what they call Wisdom?
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
Post Edited (Paul Baker (Parallax)) : 8/28/2007 5:17:29 PM GMT
Thanks!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The more I know, the more I know I don't know.· Is this what they call Wisdom?
That might be compressible to one line using intermediate assignments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
you beat me to it... (grin)
In other words, if Ken is only using BYTE variables all he needs in his routine is...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Post Edited (Beau Schwabe (Parallax)) : 8/28/2007 10:06:56 PM GMT
I'm visualizing it. You have four XOR gates, feeding into two XOR gates, feeding into one XOR gate.
or.... ((b7 ^ b6) ^ (b5 ^ b4)) ^ ((b3 ^ b2)^(b1 ^ b0))
Ken
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The more I know, the more I know I don't know.· Is this what they call Wisdom?
However there is a "by product" of many more results, as always 32 bits are XORed. This a why the last &1 is needed.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Thanks again, Gentlemen. It's nice to have some brainstorming going on [noparse]:)[/noparse]
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The more I know, the more I know I don't know.· Is this what they call Wisdom?
(1) YOU gave the STRUCTURE of the process using the parentheses.
(2) The XOR operation is associative and communicative, therefor you can ommit all parantheses
(3) So it becomes obvious that the process is correct, as anyone can see.
(4) You did not describe the process absolutely correctly, as there is more going on in the program than your formula shows.
b0 := ((b7 ^ b3) ^ (b5 ^ b1)) ^ ((b2 ^ b6) ^ (b4 ^ b0))
Like I said before, the parentheses were to show the order of computation. For instance, b7 ^ b3 in the first operation. I realize that each operation is calculating a full 32 bits, but we don't care what the result is for anything above b3 after the first XOR, or anything above b1 after the second XOR, or anything above b0 after the third XOR. Hence the "& 1" at the end - it just cleans up the result.
Am I still missing something?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The more I know, the more I know I don't know.· Is this what they call Wisdom?
Yes, this is the Amazon link to Hacker's Delight. All reviews give it 5 stars. I purchased it on a recommendation here, from Cliff Biffle.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Alas that lob softball pitch for hoped for pithy paragraph was whiffed, but I did order it last night on the basis of the first reviewer's opinion of Donald Knuth. I am looking forward to curling up with it and the prop ide and reading it through. Just as soon as I get something other than led's to show a program is doing something. (Lazy much?)
Fred