From 2f2998d02e1df057c90cbca5034cf03cc7ec7e78 Mon Sep 17 00:00:00 2001 From: Dennis Sheirer Date: Thu, 5 Oct 2023 03:20:17 -0400 Subject: [PATCH] #1661 Resolves issue with parsing of DMR embedded GPS latitude and longitude values. --- .../github/dsheirer/bits/BinaryMessage.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/main/java/io/github/dsheirer/bits/BinaryMessage.java b/src/main/java/io/github/dsheirer/bits/BinaryMessage.java index 23d950846..96c19d925 100644 --- a/src/main/java/io/github/dsheirer/bits/BinaryMessage.java +++ b/src/main/java/io/github/dsheirer/bits/BinaryMessage.java @@ -844,13 +844,18 @@ public int getInt(int start, int end) */ public int getTwosComplement(int start, int end) { - BinaryMessage sub = getSubMessage(start, end); - boolean negative = sub.get(start); - sub.flip(0, sub.size()); - - int value = sub.getInt(0, sub.size()) + 1; - value *= (negative ? -1 : 1); - return value; + if(get(start)) + { + //Negative value - flip and add one + BinaryMessage fragment = getSubMessage(start, end); + fragment.flip(0, fragment.size()); + return fragment.getInt(1, fragment.size()) + 1; + } + else + { + //Positive value - return the contents. + return getInt(start + 1, end); + } }