Jump to content

XORing bytes (for LRC calculation)


This topic is 5090 days old. Please don't post here. Open a new topic instead.

Recommended Posts

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?

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This topic is 5090 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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.