June 12, 201015 yr 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?
June 12, 201015 yr 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 )
June 12, 201015 yr Author 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!
June 12, 201015 yr Author 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.
June 12, 201015 yr 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.
Create an account or sign in to comment