0

I ran in to some Problems when I try to do this:

public byte[] Login()
    {
        return Encoding.ASCII.GetBytes("WA\x01\x00\x00\x19\xf8\x05\x01\xa0\x8a\x84\xfc\x11iPhone-2.6.7-5222\x00\x08\xf8\x02\x96\xf8\x01\xf8\x01\x7e\x00\x07\xf8\x05\x0f\x5a\x2a\xbd\xa7");
    }

these bytes \x8a\x84 get both encoded to \xbf\xbf what I do not want. I already tried with Default Encoding, UTF and Unicode, but they all do not provide what I need.

This is a socket client.

2 Answers 2

3

but they all do not provide what I need

Well we've no idea what you actually do need.

If you're trying to get the byte values 0x8a and 0x84 then I suggest you avoid using text to start with - it doesn't look like this is really all text data in the first place. It looks like there are probably bits of text within it, and you could use an encoding for those aspects, but otherwise when you want fixed binary data, you should specify that as bytes, rather than decoding "text" which isn't really text.

It's possible that using Encoding.GetEncoding(28591) (ISO-8859-1) you'll get what you were expecting, but it's still not what you should be doing.

Sign up to request clarification or add additional context in comments.

3 Comments

"WA\x01\x00\x00\x19\xf8\x05\x01\xa0\x8a\x84\xfc\x11iPhone-2.6.7-5222\x00\x08\xf8\x02\x96\xf8\x01\xf8\x01\x7e\x00\x07\xf8\x05\x0f\x5a\x2a\xbd\xa7" should be exactly the same, but as byte.
Encoding.GetEncoding(28591).GetBytes hit it. Thanks!
@Moritz: But that's not the right way of doing it, as I said before. Fundamentally you're not trying to represent Unicode U+008A for example (control character "line tabulation set") - you're trying to represent the byte 0x8a. So don't put it into text to start with.
1

ASCII is not defined above value 127.

I would wonder why you are using a string intermediary to convert bytes to bytes.

You could, instead, do something like this and eliminate this problem altogether.

Encoding.ASCII.GetBytes("WA")
.Concat(new byte[] { 1, 2, 3, 4, 5 })
.Concat(Encoding.ASCII.GetBytes("iPhone-2.6.7-5222"))
.Concat(new byte[] { 6, 7, 8, 9, 10 })
.ToArray()

1 Comment

"I already tried with Default Encoding, UTF and Unicode, but they all do not provide what I need."

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.