2012-09-13 11:09 AM
There is no builtin function in Flex to perform an xor. However, you can still perform an xor (it's just tedious).
The following Flex snippet xor's two 1-byte values (varA and varB) into a third (varXor). This builds on my earlier post "Flex: if-else logic". It could be extended to xor values up to 8 bytes (flex supports number-type variables up to 64 bits).
<assign name="varXor" value="0"/>
<assign name="checkA" value="0"/>
<assign name="checkB" value="0"/>
<if name="varA" and="1">
<assign name="checkA" value="1"/>
<if name="varB" and="1">
<assign name="checkB" value="1"/>
</if>
<if name="checkB" equal="0">
<or name="varXor" value="1"/>
</if>
</if>
<if name="checkA" equal="0">
<if name="varB" and="1">
<or name="varXor" value="1"/>
</if>
</if>
<assign name="checkA" value="0"/>
<assign name="checkB" value="0"/>
<if name="varA" and="2">
<assign name="checkA" value="1"/>
<if name="varB" and="2">
<assign name="checkB" value="1"/>
</if>
<if name="checkB" equal="0">
<or name="varXor" value="2"/>
</if>
</if>
<if name="checkA" equal="0">
<if name="varB" and="2">
<or name="varXor" value="2"/>
</if>
</if>
<assign name="checkA" value="0"/>
<assign name="checkB" value="0"/>
<if name="varA" and="4">
<assign name="checkA" value="1"/>
<if name="varB" and="4">
<assign name="checkB" value="1"/>
</if>
<if name="checkB" equal="0">
<or name="varXor" value="4"/>
</if>
</if>
<if name="checkA" equal="0">
<if name="varB" and="4">
<or name="varXor" value="4"/>
</if>
</if>
<assign name="checkA" value="0"/>
<assign name="checkB" value="0"/>
<if name="varA" and="8">
<assign name="checkA" value="1"/>
<if name="varB" and="8">
<assign name="checkB" value="1"/>
</if>
<if name="checkB" equal="0">
<or name="varXor" value="8"/>
</if>
</if>
<if name="checkA" equal="0">
<if name="varB" and="8">
<or name="varXor" value="8"/>
</if>
</if>
<assign name="checkA" value="0"/>
<assign name="checkB" value="0"/>
<if name="varA" and="16">
<assign name="checkA" value="1"/>
<if name="varB" and="16">
<assign name="checkB" value="1"/>
</if>
<if name="checkB" equal="0">
<or name="varXor" value="16"/>
</if>
</if>
<if name="checkA" equal="0">
<if name="varB" and="16">
<or name="varXor" value="16"/>
</if>
</if>
<assign name="checkA" value="0"/>
<assign name="checkB" value="0"/>
<if name="varA" and="32">
<assign name="checkA" value="1"/>
<if name="varB" and="32">
<assign name="checkB" value="1"/>
</if>
<if name="checkB" equal="0">
<or name="varXor" value="32"/>
</if>
</if>
<if name="checkA" equal="0">
<if name="varB" and="32">
<or name="varXor" value="32"/>
</if>
</if>
<assign name="checkA" value="0"/>
<assign name="checkB" value="0"/>
<if name="varA" and="64">
<assign name="checkA" value="1"/>
<if name="varB" and="64">
<assign name="checkB" value="1"/>
</if>
<if name="checkB" equal="0">
<or name="varXor" value="64"/>
</if>
</if>
<if name="checkA" equal="0">
<if name="varB" and="64">
<or name="varXor" value="64"/>
</if>
</if>
<assign name="checkA" value="0"/>
<assign name="checkB" value="0"/>
<if name="varA" and="128">
<assign name="checkA" value="1"/>
<if name="varB" and="128">
<assign name="checkB" value="1"/>
</if>
<if name="checkB" equal="0">
<or name="varXor" value="128"/>
</if>
</if>
<if name="checkA" equal="0">
<if name="varB" and="128">
<or name="varXor" value="128"/>
</if>
</if>
2012-09-18 08:53 PM
Color me impressed for figuring out how to xor data (up to 8 bytes) in XML. You never cease to amaze me. +1 vote for a new Ninja level that is only held by you in this forum.
2012-09-20 02:36 PM
I second Sconzo's remark. This is exceptional work! This is useful in a number of ways. I'm guessing since you are only using if statements and avoided reads, finds, and such this is rather fast?
2012-09-20 06:15 PM
Thanks!
Yeah, it should be fast. There is a little bit of a performance penalty for each "if". But you can't really write a parser without them...