Forum Index
HomeZBasic Home   Forum RulesForum Rules   Forum FAQForum FAQ   MemberlistMemberlist   UsergroupsUsergroups   RSS FeedRSS Feed
Site SearchSite Search   LinksLinks   DownloadDownload   Digests and SubscriptionsDigests and Subscriptions
ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in   RegisterRegister
Serial/linear XOR

 
Post new topic   Reply to topic    Forum Index -> ZX-24
Author Message
GTBecker



Joined: 18 Jan 2006
Posts: 457
Location: Cape Coral

Posted: 24 February 2009, 16:41 PM    Post subject: Serial/linear XOR Reply with quote

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 Reply with quote

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 Reply with quote

> ... 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
Display posts from previous:   
Post new topic   Reply to topic    Forum Index -> ZX-24 Time synchro. with the server - Timezone/DST with your computer
Page 1 of 1

 


All content Copyright © 2005-2012 Elba Corp. All Rights Reserved.
Opinions expressed in posts are those of the author and not necessarily those of Elba Corp.
Powered by phpBB © 2001, 2005 phpBB Group