Readbytes from files.

kkingstoun

Member
Licensed User
Longtime User
Hi, I saved data bits from Bluetooth device to the file puls.bin.

I would like to read all of these bits like as protocol:

Special I need to read 3 byte - wave pulse.

2hygb4i.jpg


How could I read these from file?
 
Last edited:

kkingstoun

Member
Licensed User
Longtime User
Erel thanks for answer, but it don't help me. In Wiki and forum I have not seen information how to read individual bits.
I need to read from byte 3 bit 0-6 (range 0.0 - 7F) and check boolen bit 7 - true or not. It's possible in basic4andoid?

byte converter works good but i think i have got problem with sign and unsigned bits, becouse max value what's i get after conversion is 191.

262mvea.png
 
Last edited:
Upvote 0

MLDev

Active Member
Licensed User
Longtime User
You could try this:

B4X:
bits06 = Bit.AND(byte3, 0x7f)

B4X:
Log("Bit 7 is " & getBit(byte3, 7))
...

Sub getBit(fromByte As Int, BitNo As Int) As Boolean
   Return Bit.ShiftRight(Bit.AND(fromByte, Power(2, BitNo)), BitNo) = 1
End Sub
 
Upvote 0

kkingstoun

Member
Licensed User
Longtime User
Ok, thanks I write somethink like that, and it works.
PHP:
Writer.WriteLine(fala)
these save me only one last line.

PHP:
Sub Strumien_NewData (Buffer() As Byte)
Dim byte3,bits06 As Int
   byte3 = Buffer(3)         ; It's must be 3...
   byte3 = Bit.AND(byte3, 0x7f)
   fala = byte3
 
Last edited:
Upvote 0
Top