You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by cd...@apache.org on 2020/01/27 08:14:06 UTC
[plc4x] branch develop updated: - Fixed a bug reading one bit too
little, causing the entire stream to be offset by one bit.
This is an automated email from the ASF dual-hosted git repository.
cdutz pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git
The following commit(s) were added to refs/heads/develop by this push:
new b1a9b64 - Fixed a bug reading one bit too little, causing the entire stream to be offset by one bit.
b1a9b64 is described below
commit b1a9b641aaba271e2c19a579219a85ae9437a89d
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Mon Jan 27 09:13:52 2020 +0100
- Fixed a bug reading one bit too little, causing the entire stream to be offset by one bit.
---
.../main/java/org/apache/plc4x/java/spi/generation/StaticHelper.java | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/StaticHelper.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/StaticHelper.java
index 858e516..4f0ddb0 100644
--- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/StaticHelper.java
+++ b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/StaticHelper.java
@@ -98,9 +98,10 @@ public class StaticHelper {
public static double toFloat(ReadBuffer io, boolean signed, int bitsExponent, int bitsMantissa) {
try {
boolean negative = (signed) && io.readBit();
- long exponent = io.readUnsignedLong(bitsExponent) - (((long) Math.pow(2, bitsExponent) / 2) - 1);
+ long exponent = io.readUnsignedLong(bitsExponent);
+ exponent = exponent - (((long) Math.pow(2, bitsExponent) / 2) - 1);
double mantissa = 1D;
- for(int i = 1; i < bitsMantissa; i++) {
+ for(int i = 1; i <= bitsMantissa; i++) {
if(io.readBit()) {
mantissa += Math.pow(2, (double) i * -1);
}