Android Question Randomaccessfile: Reading unsigned integer

grafsoft

Well-Known Member
Licensed User
Longtime User
Hi,

I am reading an int with the readint method of RandomAccessFile. Now I have a negative integer, but what I need is an unsignedd int. I have trie3d to add different powers of 2, but to no avail.

Thanks for your help!

Peter
 

DonManfred

Expert
Licensed User
Longtime User
Using the forumsearch COULD HAVE HELPED. It is working!

B4X:
Sub ToUnsigned(b As Byte) As Int
   Return Bit.And(0xFF, b)
End Sub

'check:
Log(Bit.ToHexString(ToUnsigned(0xAA)))
 
Upvote 0

grafsoft

Well-Known Member
Licensed User
Longtime User
Thank you, but it does not work. Start, choose the number 1 and press OK. Line 80 in main.b4a.
 

Attachments

  • bintest.zip
    60.3 KB · Views: 322
Upvote 0

grafsoft

Well-Known Member
Licensed User
Longtime User
No. But I have a value of -400818176, which is converted into -4.00818176E8

Unsigned should be positive, I think a value of about 7000 should come out.
 
Upvote 0

grafsoft

Well-Known Member
Licensed User
Longtime User
Still does not work, produces -400818176. I made a little project that does only use this function and added it to this post.
 

Attachments

  • test2.zip
    7.1 KB · Views: 320
Upvote 0
Top