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.
This commit is contained in:
parent
91dae1be7e
commit
610ccc630a
1 changed files with 2 additions and 1 deletions
|
@ -99,7 +99,8 @@ public class Arduino_Com : MonoBehaviour
|
||||||
} while (checksumRead < 2);
|
} while (checksumRead < 2);
|
||||||
|
|
||||||
// Implicit type of the sum is 4 bytes, so the overflow doesn't occur. Compute manually.
|
// 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.
|
// Checksum valid, write it out to the cart.
|
||||||
_cart.Write(_pageBuffer);
|
_cart.Write(_pageBuffer);
|
||||||
|
|
Loading…
Add table
Reference in a new issue