iOS Question bit.and

Samplatiner

Member
Licensed User
Longtime User
Hello,

I have written a App with b4A for a communication with a SPS.

Therefore I wrote a Sub for converting a Siemens-Real in a normal double. This Sub is doing a good Job.

Now I write this App with b4i for iOS, but with b4i the Sub crashes. The problem is the Bit.And-Operation

B4X:
Sub ByteToDouble(byteArray() AsByte) AsDouble
Dim negativ AsInt=Bit.AND(byteArray(0), 128)/128
Dim factor AsInt=0
If negativ=1Then
factor=-1
ElseIf negativ=0Then
factor=1
EndIf
'calculate exponent
Dim exponent AsInt=Bit.AND(byteArray(0), 64)*2
exponent=exponent + Bit.AND(byteArray(0), 32)*2
exponent=exponent + Bit.AND(byteArray(0), 16)*2
exponent=exponent + Bit.AND(byteArray(0), 8)*2
exponent=exponent + Bit.AND(byteArray(0), 4)*2
exponent=exponent + Bit.AND(byteArray(0), 2)*2
exponent=exponent + Bit.AND(byteArray(0), 1)*2
exponent=exponent + Bit.AND(byteArray(1), 128)/128
exponent=exponent-127
exponent=Power(2, exponent)
'calculate mantisse
Dim mantisse AsDouble=0
mantisse=mantisse+Bit.AND(byteArray(3),1)
mantisse=mantisse+Bit.AND(byteArray(3),2)
mantisse=mantisse+Bit.AND(byteArray(3),4)
mantisse=mantisse+Bit.AND(byteArray(3),8)
mantisse=mantisse+Bit.AND(byteArray(3),16)
mantisse=mantisse+Bit.AND(byteArray(3),32)
mantisse=mantisse+Bit.AND(byteArray(3),64)
mantisse=mantisse+Bit.AND(byteArray(3),128)
mantisse=mantisse+Bit.AND(byteArray(2),1)*256
mantisse=mantisse+Bit.AND(byteArray(2),2)*256
mantisse=mantisse+Bit.AND(byteArray(2),4)*256
mantisse=mantisse+Bit.AND(byteArray(2),8)*256
mantisse=mantisse+Bit.AND(byteArray(2),16)*256
mantisse=mantisse+Bit.AND(byteArray(2),32)*256
mantisse=mantisse+Bit.AND(byteArray(2),64)*256
mantisse=mantisse+Bit.AND(byteArray(2),128)*256
mantisse=mantisse+Bit.AND(byteArray(1),1)*256*256
mantisse=mantisse+Bit.AND(byteArray(1),2)*256*256
mantisse=mantisse+Bit.AND(byteArray(1),4)*256*256
mantisse=mantisse+Bit.AND(byteArray(1),8)*256*256
mantisse=mantisse+Bit.AND(byteArray(1),16)*256*256
mantisse=mantisse+Bit.AND(byteArray(1),32)*256*256
mantisse=mantisse+Bit.AND(byteArray(1),64)*256*256
mantisse=mantisse/Power(2, 23)
mantisse=mantisse+1
Return factor*mantisse*exponent
End Sub

But the Bit.And-Operations all fail. Here the error code:

Application_Start
Application_Active
Error occurred on line: 84 (datatypeconversion)
Target is null. Method called: Bit
Stack Trace: (
CoreFoundation <redacted> + 150
libobjc.A.dylib objc_exception_throw + 38
CoreFoundation <redacted> + 0
Optima +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 178
Optima -[B4IShell runMethod:] + 496
Optima -[B4IShell raiseEventImpl:method:args::] + 1768
Optima -[B4IShellBI raiseEvent:event:params:] + 1332
Optima __50-[B4I raiseEventFromDifferentThread:event:params:]_block_invoke + 74
libdispatch.dylib <redacted> + 10
libdispatch.dylib <redacted> + 22
libdispatch.dylib _dispatch_main_queue_callback_4CF + 718
CoreFoundation <redacted> + 8
CoreFoundation <redacted> + 1512
CoreFoundation CFRunLoopRunSpecific + 476
CoreFoundation CFRunLoopRunInMode + 106
GraphicsServices GSEventRunModal + 136
UIKit UIApplicationMain + 1440
Optima main + 108
libdyld.dylib <redacted> + 2
)

The line 84 from the error-text is the first Bit.And-Operation.
Datatypeconversion is a class module i wrote for a few conversions from byteArrays to values.

The incoming value is 0.0, so there are 4 Bytes with value 0.

I would be very happy if someone could give me a hint.

Best regards,
Daniel
 

JanPRO

Well-Known Member
Licensed User
Longtime User
Upvote 0
Top