|
|
| Author |
Message |
GTBecker
Joined: 18 Jan 2006
Posts: 457
Location: Cape Coral
|
|
Posted: 24 February 2009, 16:41 PM Post subject: Serial/linear XOR |
|
|
I need to Xor all of the one bits in a Long, serially. That is equivalent to bit zero in a count of the ones, isn't it? E.g. &h10204090 has five ones, so the unit bit of the count of five is high, the same as the serial Xor of the bits.
Is there another method?
Tom |
|
| Back to top |
|
 |
dkinzer Site Admin
Joined: 03 Sep 2005
Posts: 2499
Location: Portland, OR
|
|
Posted: 24 February 2009, 17:10 PM Post subject: Re: Serial/linear XOR |
|
|
| GTBecker wrote: | | That is equivalent to bit zero in a count of the ones, isn't it? | Yes. It is also similar to a parity calculation. You can probably get the desired result using the ParityCheck() function. An untested example that may do what you need is given below. An alternate strategy, which will probably be faster, would be to calculate the one's complement sum (Xor) of the bytes in the data stream and then perform a ParityCheck() call on the result. | Code: | Dim l as Long
Dim isOdd as Boolean
Sub Main()
isOdd = Parity(l.DataAddress, CByte(SizeOf(l)))
End Sub
Function Parity(ByVal addr as UnsignedInteger, ByVal cnt as Byte) As Boolean
Dim b as Byte Based addr
Parity = false
' compute the bit parity over the entire data stream
Do While (cnt > 0)
If (ParityCheck(b, true)) Then
Parity = Not Parity
End If
addr = addr + 1
cnt = cnt - 1
Loop
End Function
|
|
|
| Back to top |
|
 |
GTBecker
Joined: 18 Jan 2006
Posts: 457
Location: Cape Coral
|
|
Posted: 24 February 2009, 17:19 PM Post subject: Serial/linear XOR |
|
|
> ... similar to a parity calculation...
Thanks for the confirmation, Don. In fact, this _is_ part of a parity
check, a six-bit parity for 24 bits of data in a raw DGPS stream. I get
the data in 30-bit words in parallel, the standard GPS parsing.
Tom |
|
| Back to top |
|
 |
|