jasonwood Posted June 12, 2010 Posted June 12, 2010 I am trying to figure out how to XOR two bytes together in FileMaker. Example: I start with the binary values 49 and 50 which would be represented in binary as 00110001 and 00110010. I want to XOR them together (matching bits become 0 and different ones become 1) so that I end up with 3 (binary representation 00000011). This is needed in order to calculate an LRC (Longitudinal Redundancy Check), which I need to append to my serial commands (using troi serial plugin) to a credit card terminal. Where do I start?
comment Posted June 12, 2010 Posted June 12, 2010 Try: BitwiseXOR ( n ; m ) = Let ( [ bitXOR = Mod ( n ; 2 ) xor Mod ( m ; 2 ) ; nextN = Div ( n ; 2 ) ; nextM = Div ( m ; 2 ) ] ; Case ( nextN or nextM ; 2 * BitwiseXOR ( nextN ; nextM ) ) + bitXOR )
jasonwood Posted June 12, 2010 Author Posted June 12, 2010 well I don't really understand it but it works and it's WAY better than my brute force solution: Let ([$byte1=byte1;$byte2=byte2];"") & If ( ( ( $byte1 ) ≥ 128 ) xor ( ( $byte2 ) ≥ 128 ) ; "1" ; "0" ) & If ( $byte1 ≥ 128 ; Let ($byte1=$byte1-128;"") ; "" ) & If ( $byte2 ≥ 128 ; Let ($byte2=$byte2-128;"") ; "" ) & If ( ( ( $byte1 ) ≥ 64 ) xor ( ( $byte2 ) ≥ 64 ) ; "1" ; "0" ) & If ( $byte1 ≥ 64 ; Let ($byte1=$byte1-64;"") ; "" ) & If ( $byte2 ≥ 64 ; Let ($byte2=$byte2-64;"") ; "" ) & If ( ( ( $byte1 ) ≥ 32 ) xor ( ( $byte2 ) ≥ 32 ) ; "1" ; "0" ) & If ( $byte1 ≥ 32 ; Let ($byte1=$byte1-32;"") ; "" ) & If ( $byte2 ≥ 32 ; Let ($byte2=$byte2-32;"") ; "" ) & If ( ( ( $byte1 ) ≥ 16 ) xor ( ( $byte2 ) ≥ 16 ) ; "1" ; "0" ) & If ( $byte1 ≥ 16 ; Let ($byte1=$byte1-16;"") ; "" ) & If ( $byte2 ≥ 16 ; Let ($byte2=$byte2-16;"") ; "" ) & If ( ( ( $byte1 ) ≥ 8 ) xor ( ( $byte2 ) ≥ 8 ) ; "1" ; "0" ) & If ( $byte1 ≥ 8 ; Let ($byte1=$byte1-8;"") ; "" ) & If ( $byte2 ≥ 8 ; Let ($byte2=$byte2-8;"") ; "" ) & If ( ( ( $byte1 ) ≥ 4 ) xor ( ( $byte2 ) ≥ 4 ) ; "1" ; "0" ) & If ( $byte1 ≥ 4 ; Let ($byte1=$byte1-4;"") ; "" ) & If ( $byte2 ≥ 4 ; Let ($byte2=$byte2-4;"") ; "" ) & If ( ( ( $byte1 ) ≥ 2 ) xor ( ( $byte2 ) ≥ 2 ) ; "1" ; "0" ) & If ( $byte1 ≥ 2 ; Let ($byte1=$byte1-2;"") ; "" ) & If ( $byte2 ≥ 2 ; Let ($byte2=$byte2-2;"") ; "" ) & If ( ( ( $byte1 ) ≥ 1 ) xor ( ( $byte2 ) ≥ 1 ) ; "1" ; "0" ) Thanks!
jasonwood Posted June 12, 2010 Author Posted June 12, 2010 I don't suppose that could be modified to do the whole sequence of comparisons (I was going to use a scripted loop for this. Basically I'm XORing a lot more than 2 values, which would come from one field (with a separator or carriage return, whatever works best). First XOR the first two, then XOR the result with the next value, and so forth until the last value.
comment Posted June 12, 2010 Posted June 12, 2010 I think it would be better to use another custom function for the "sequencing". This function would call the first function to do the XORing.
Recommended Posts
This topic is 5276 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now