BBC BASIC for Windows
Programming >> BBC BASIC language >> Parity Check
http://bb4w.conforums.com/index.cgi?board=language&action=display&num=1395263088

Parity Check
Post by Wendell on Mar 19th, 2014, 9:04pm

Richard i have been using the Tutorial a great help too, but i couldnt find anything about a comand to check for Parity of a number, or if there is a command. Sorry to bother you i am almost done.
Re: Parity Check
Post by rtr on Mar 19th, 2014, 9:45pm

on Mar 19th, 2014, 9:04pm, Wendell wrote:
i couldnt find anything about a comand to check for Parity of a number

This is the fastest method I know (for 32-bit integers); it returns 0 for even parity and 1 for odd parity:

Code:
      DEF FNparity(X%)
      X% EOR= X% >> 1
      X% EOR= X% >> 2
      X% EOR= X% >> 4
      X% EOR= X% >> 8
      X% EOR= X% >> 16
      = X% AND 1 

Richard.