Android Question how to serialize the int 128 using BytesToString

b4xfr

Member
Licensed User
Basically i try to encode a number into a string.
It work with 127, but not with 128.
b4a byte is signed, and so 127 is the maximum value for a b4a byte, even if internally a signed byte is similar to an unsigned byte.
but an int can contains this value...

If someone can help, thank you.

Here is the code that i put in the main module :

Dim number As Int = 128

'write an int into a 4 bytes array
Dim b(4) As Byte
Dim r As RandomAccessFile
r.Initialize3( b, False )
r.WriteInt( number, r.CurrentPosition )
r.Close

'see what we have in the array
Dim bc As ByteConverter
Log( bc.HexFromBytes( b ) )'output 00000080 it is ok

'convert the byte array into a string
Dim s As String = BytesToString( b, 0, 4, "US-ASCII" )

'see what we have in this string by coming back to an array
b = s.GetBytes( "US-ASCII" )
'b = bc.StringToBytes( s, "US-ASCII")'alternative way
Log( bc.HexFromBytes( b ) )'--> output 0000003F so it is wrong, it is the number 63

'read the array as an int
r.Initialize3(b, False )
Dim u2 As Int = r.ReadInt(0)
Log(u2)'output 63
 

Similar Threads

D
  • Question
Replies
9
Views
3K
Deleted member 103
D
Replies
0
Views
6K
Replies
120
Views
178K
Replies
164
Views
216K
Top