GetBytes Problem

rbsoft

Active Member
Licensed User
Longtime User
In the following piece of code the value Chr(254) is not properly translated.

B4X:
t = "&&ID|" & MyIP & "|1|42" & Chr(254)
Buffer = t.GetBytes("UTF8")
OutputStream1.WriteBytes(Buffer,0,t.Length)

The receiving program gets everything right except that Chr(254) has changed into Chr(195).

Any idea what I am doing wrong?

Rolf

PS:
Just noted in the Debugger that Chr(254) gets translated into Chr(-61) & Chr(-66). Number of bytes became 21 instead of 20.
 
Last edited:

kickaha

Well-Known Member
Licensed User
Longtime User
Chr 254 translated to unicode is two bytes C3, BE, or 195, 190 in decimal. These values translate to -61, -66 as signed 8 bit integers so things are working as they should.

Not sure what you are doing, but it seems that you need to use different encoding.
 
Upvote 0

rbsoft

Active Member
Licensed User
Longtime User
I use Chr(254) as an end delimiter in a TCP/IP protocol I am using for many years.

I tried UTF16 and ASCII encoding but without success.
 
Upvote 0

rbsoft

Active Member
Licensed User
Longtime User
How would I do that? Could you give 2 or 3 lines of code?
Somehow I am not able to grasp it.

Rolf
 
Upvote 0

rbsoft

Active Member
Licensed User
Longtime User
Thank you, Erel.

Rolf
 
Upvote 0

rbsoft

Active Member
Licensed User
Longtime User
Yep - that did the job! My communication routines work.

Thanks also, kickaha, for the information.


Rolf
 
Upvote 0
Top