Data type

Javor

New Member
Hello.

I'm evaluating B4A and am curious about data types. I need to make a small program for Android OS which communicates with my controllers using packets of bytes. So is there any unsigned data types? From what I've read byte is signed (-128 - 127), short, int and the others also. How can I declare and use an array of bytes (unsigned, i.e. 0-255). And if I buy the full version and thus use socket how can I send/receive an array of bytes? All the examples I've seen here use TextWriter for sending. It's kinda odd (the whole Java is odd btw) as I have to operate with those bytes in the array and send/receive them. Is there any way? Or some library or.. I don't know. I'm stuck :BangHead: I feel B4A won't fit my needs.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Basic4android data types are the same as the Java data types.
In both languages there is no unsigned byte type.

However you can use an array of signed bytes instead:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Dim b(10) As Byte
   b(0) = 250
   
   Log(ReadUnsignedByte(b(0))) 'will print 250
End Sub

Sub ReadUnsignedByte(Value As Byte) As Int
   Return Bit.And(Value, 0xFF)
End Sub

TextWriter should only be used when working with Strings.
See RandomAccessFile and BytesConverter libraries for examples of working with bytes.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…