From 610ccc630aa75e2185f4295e08b395c50bf701b4 Mon Sep 17 00:00:00 2001 From: Teo-CD Date: Sat, 16 Dec 2023 12:30:30 +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);