User Tools

Site Tools


finding_20the_20parity_20of_20a_20number

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
finding_20the_20parity_20of_20a_20number [2018/03/31 13:19] – external edit 127.0.0.1finding_20the_20parity_20of_20a_20number [2024/01/05 00:22] (current) – external edit 127.0.0.1
Line 2: Line 2:
  
 //by Richard Russell, March 2014//\\ \\  The **parity** of an integer is determined by the number of set (i.e. **1**) bits in its binary representation. If there are an even number of set bits the parity is **even** and if there are an odd number of set bits the parity is **odd**. So for example %00100000 has odd parity and %00100010 has even parity.\\ \\  The function below can be used to discover the parity of a 32-bit integer, it returns 0 for even parity and 1 for odd parity:\\  //by Richard Russell, March 2014//\\ \\  The **parity** of an integer is determined by the number of set (i.e. **1**) bits in its binary representation. If there are an even number of set bits the parity is **even** and if there are an odd number of set bits the parity is **odd**. So for example %00100000 has odd parity and %00100010 has even parity.\\ \\  The function below can be used to discover the parity of a 32-bit integer, it returns 0 for even parity and 1 for odd parity:\\ 
 +<code bb4w>
         DEF FNparity(X%)         DEF FNparity(X%)
         X% EOR= X% >> 1         X% EOR= X% >> 1
Line 9: Line 10:
         X% EOR= X% >> 16         X% EOR= X% >> 16
         = X% AND 1          = X% AND 1 
-An equivalent function for 64-bit integers (//BBC BASIC for Windows// version 6 only) is as follows:\\ +</code> 
 +An equivalent function for 64-bit integers is as follows:\\  
 +<code bb4w>
         DEF FNparity(X%%)         DEF FNparity(X%%)
         X%% EOR= X%% >> 1         X%% EOR= X%% >> 1
Line 18: Line 21:
         X%% EOR= X%% >> 32         X%% EOR= X%% >> 32
         = X%% AND 1          = X%% AND 1 
 +</code>
finding_20the_20parity_20of_20a_20number.1522502361.txt.gz · Last modified: 2024/01/05 00:17 (external edit)