From ba6b31dbf2c38c508219c2b7580f7f9a2a9a132f Mon Sep 17 00:00:00 2001 From: trotFunky Date: Sat, 16 Dec 2023 14:10:28 +0000 Subject: [PATCH] Unity: Use UInt16.MaxValue rather than hardcoding 65536 Unity provides constants that reflect the maximum value of integer types, use it for checking the checksum overflow rather than using 65536 directly. This makes the intent more clear. --- Assets/Scripts/Arduino_Com.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Assets/Scripts/Arduino_Com.cs b/Assets/Scripts/Arduino_Com.cs index b931200..bf7a9a3 100644 --- a/Assets/Scripts/Arduino_Com.cs +++ b/Assets/Scripts/Arduino_Com.cs @@ -99,7 +99,8 @@ public class Arduino_Com : MonoBehaviour } while (checksumRead < 2); // Implicit type of the sum is 4 bytes, so the overflow doesn't occur. Compute manually. - if (65536 - (BitConverter.ToUInt16(checksum) + ComputeChecksum(_pageBuffer)) == 0) + if ((UInt16.MaxValue + 1) - + (BitConverter.ToUInt16(checksum) + ComputeChecksum(_pageBuffer)) == 0) { // Checksum valid, write it out to the cart. _cart.Write(_pageBuffer);