GetBytes Returning Negative Numbers?

woodpecker

Member
Licensed User
Longtime User
Hi folks,

I am decoding serial data encoded in windows-1252 but it has some odd characters that need converting to plain text, with some of the chracters I am struggleing to identify them so I can replace them.

I decided to try and do a byte conversion so I could look them up, however it is returning negative numbers for the characters I cannot identify.

I am doing the following:-

B4X:
Dim data() as Byte
data = mystring.GetBytes("WINDOWS-1252")
For x = 1 To data.Length - 1
mybytes = mybytes & data(x) & CRLF
Next
panel2text.text = mybytes & CRLF

Using this code spaces show as 32 which seems correct but other characters I am trying to identify show as -124 and -125

How do I find the char code so I can replace them?
 

wdegler

Active Member
Licensed User
Longtime User
Byte range

A byte is a signed value stored in a single byte which has a binary value in the range 0 to 255.. Therefore, a value in this range greater than 127 will have the highest bit set which flags the number as negative.
 
Upvote 0
Top