Files
OpenTracks/src/main/java/de/dennisguse/opentracks/util/UintUtils.java
T
Dennis Guse ddb17f61cb Bluetooth LE: implemented cycling cadence and speed sensors.
Cadence is working while speed still requires the wheel size.
2020-04-27 07:17:46 +02:00

31 lines
615 B
Java

package de.dennisguse.opentracks.util;
public class UintUtils {
public static int UINT16_MAX = 0xFFFF;
public static long UINT32_MAX = 0xFFFFFFFFL;
private UintUtils() {
}
/**
* Computes a - b for UINT with overflow (b < a).
*
* @return diff or -1 (invalid)
*/
public static long diff(long a, long b, final long UINT_MAX) {
if (a < 0 || b < 0) {
return -1;
}
if (a > UINT_MAX && b > UINT_MAX) {
return -1;
}
if (a >= b) {
return a - b;
}
return (UINT_MAX - b) + a;
}
}