Difference between revisions of "Template:HasBitValueSet"

From RadiWiki
Jump to: navigation, search
(Created page with '<!-- Determines if a bit value is set in a value -->{{#ifeq:{{#expr:{{{1}}} mod ({{{2}}} * 2)}}|{{#expr:({{{1}}} mod ({{{2}}} * 2)) mod {{{2}}}}}|0|1}}<noinclude> It seems to be …')
 
 
Line 1: Line 1:
<!-- Determines if a bit value is set in a value -->{{#ifeq:{{#expr:{{{1}}} mod ({{{2}}} * 2)}}|{{#expr:({{{1}}} mod ({{{2}}} * 2)) mod {{{2}}}}}|0|1}}<noinclude>
+
<!-- Determines if a bit value is set in a value -->{{#ifeq:{{#expr:{{{1}}} mod ({{{2}}} * 2)}}|{{#expr:({{{1}}} mod ({{{2}}} * 2)) mod {{{2}}}}}|0|1}}<noinclude>It seems to be very difficult in MediaWiki to implement bit operations (or bitwise comparsion).
It seems to be very difficult in MediaWiki to implement bit operations (or bitwise comparsion).
 
  
 
A possibility is to use a modulation operation of the double of the value, to determine if the value is present.
 
A possibility is to use a modulation operation of the double of the value, to determine if the value is present.

Latest revision as of 20:16, 28 June 2016

0It seems to be very difficult in MediaWiki to implement bit operations (or bitwise comparsion).

A possibility is to use a modulation operation of the double of the value, to determine if the value is present. 10 is bitvalue 8 and bitvalue 2. To check if bitvalue 2 is set double the bitvalue, and use it for the a modulo operation. Then with that result, do a modulo operation with the tested bitvalue. If it changes, then the bit was set.

  • 10 mod (2 * 2) => 2
  • 2 mod 2 => 0
  • 0 is different than the 2, so the bitvalue 2 was present in 10.