Android Question Signed & Unsigned bytes confusion

JTmartins

Active Member
Licensed User
Longtime User
Hi, I guess this question is pretty easy for some guys out there, but is puzzling me.

I'm trying to interface a fingerprint reader from SparkFun using an FTDI chip in the middle.

I have the documentation, commands, etc.

Usb conection to the fingerprint reader is working, however when I send the open command and receive the reply bytes in the buffer I get the following :

Byte 1 = 0x55
Byte 2 = 0XFFFFFFAA
..etc

I know the first byte is correct (0x55) but the second byte should be only AA.
I do understand that this is a signed value and I've worked with them in the past

All the negative values I'm getting look like 32bit values and not bytes

Why amd I getting a 32bit value and not a byte ?

How do I convert this FFFFFFAA to AA, as the usual "bit.and" does not do the trick here.

Many Thanks

J.Martins
 

JTmartins

Active Member
Licensed User
Longtime User
Many thanks Johan and Erel.

I found my mistake.

I was doing

B4X:
Private a(Buffer.Length) As byte

For f=0 To Buffer.Length-1
       a(f)=SignedConverter(Buffer(f))
Next

So I was getting the same 0XFFFFFFAA after SignedConverter.
Changed to

B4X:
Private a(Buffer.Length) As Int
For f=0 To Buffer.Length-1
    a(f)=SignedConverter(Buffer(f))
Next

and all is OK now. Variable a, had to be defined as integer and not as byte.
 
Upvote 0
Top