Skip to content

Commit c836270

Browse files
committed
#740 Simplify unsigned binary to long conversion when values can't be negative.
1 parent 1b42a38 commit c836270

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

cobol-parser/src/main/scala/za/co/absa/cobrix/cobol/parser/decoders/BinaryNumberDecoders.scala

+2-4
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ object BinaryNumberDecoders {
8686
if (bytes.length < 4) {
8787
return null
8888
}
89-
val v: Long = ((bytes(0) & 255L) << 24L) | ((bytes(1) & 255L) << 16L) | ((bytes(2) & 255L) << 8L) | (bytes(3) & 255L)
90-
if (v<0) null else v
89+
((bytes(0) & 255L) << 24L) | ((bytes(1) & 255L) << 16L) | ((bytes(2) & 255L) << 8L) | (bytes(3) & 255L)
9190
}
9291

9392
def decodeBinaryUnsignedIntLittleEndian(bytes: Array[Byte]): Integer = {
@@ -102,8 +101,7 @@ object BinaryNumberDecoders {
102101
if (bytes.length < 4) {
103102
return null
104103
}
105-
val v: Long = ((bytes(3) & 255L) << 24L) | ((bytes(2) & 255L) << 16L) | ((bytes(1) & 255L) << 8L) | (bytes(0) & 255L)
106-
if (v<0) null else v
104+
((bytes(3) & 255L) << 24L) | ((bytes(2) & 255L) << 16L) | ((bytes(1) & 255L) << 8L) | (bytes(0) & 255L)
107105
}
108106

109107
def decodeBinarySignedLongBigEndian(bytes: Array[Byte]): java.lang.Long = {

0 commit comments

Comments
 (0)