I had a need to XOR decimal numbers and I couldn't find anything on the collab forum, so I whipped it out here. While I was at it, I created AND, and OR functions. That is - the standard Binary And, OR and XOR functions applied to decimal numbers. The decimal numbers are converted into binary arrays, the binary operations applied to the arrays, and then the arrays are converted back to binary.
XORing decimals can be used as a form of validation (used in Raid5 for computer hard drives). It is also frequently used in various check-sums.
I actually needed all this in working through a variable that can hold multiple values.
For example I might create these variables:
Debtor := 1
Creditor := 2
Internal := 4
External := 8
Note - these are all base 2.
That is - a piece of information might relate to a debtor and/or a creditor and/or be internal and/or be external. No options are mutually exclusive
To add information to a variable:
x := DecOR(x, Debtor)
This is, x is now related to Debtor - whether it was before or not, and irrespective of what other information is already in x.
x := DecOR(x, External)
This is now related to external. Assuming these are the only two assignments, x is now recording "external" and "debtor".
If the state of x is known to be zero (unassigned), x could have been assigned like this:
x := Debtor + External
Now - if I have debtor specific function I can pull the information out of x:
XXXX If DecAnd(x, Debtor) = Debtor
Or - if I want all options EXCEPT Debtor:
XXXX If DecAND(x, Debtor) = 0
If I want all Debtor and Creditor - irrespective of internal/external:
XXXX If DecOR(X, DecOR(Debtor,Creditor)) > 0
If I decide that x is no longer to be related to external, I would use:
x := DecXOR(x, External) If DecAnd(x, External) = External
Philip
___________________
Correct answers don't require correct spelling.
XORing decimals can be used as a form of validation (used in Raid5 for computer hard drives). It is also frequently used in various check-sums.
I actually needed all this in working through a variable that can hold multiple values.
For example I might create these variables:
Debtor := 1
Creditor := 2
Internal := 4
External := 8
Note - these are all base 2.
That is - a piece of information might relate to a debtor and/or a creditor and/or be internal and/or be external. No options are mutually exclusive
To add information to a variable:
x := DecOR(x, Debtor)
This is, x is now related to Debtor - whether it was before or not, and irrespective of what other information is already in x.
x := DecOR(x, External)
This is now related to external. Assuming these are the only two assignments, x is now recording "external" and "debtor".
If the state of x is known to be zero (unassigned), x could have been assigned like this:
x := Debtor + External
Now - if I have debtor specific function I can pull the information out of x:
XXXX If DecAnd(x, Debtor) = Debtor
Or - if I want all options EXCEPT Debtor:
XXXX If DecAND(x, Debtor) = 0
If I want all Debtor and Creditor - irrespective of internal/external:
XXXX If DecOR(X, DecOR(Debtor,Creditor)) > 0
If I decide that x is no longer to be related to external, I would use:
x := DecXOR(x, External) If DecAnd(x, External) = External
Philip
___________________
Correct answers don't require correct spelling.