Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

XORing bytes (for LRC calculation)

Featured Replies

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?

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

)

  • 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!

  • 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.

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.