I want to create a data packet and write it to socket.
This packet starts with ‘C0’ hex value.
In php I easily can create it with this code:
$a = "\xC0";
now I want to create it in c#. How can do this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In C#, strings are Unicode-encoded, so you shouldn’t use them for binary data. Instead use a byte array.
To create a byte array starting with C0, do something like this:
If you have an existing string that you want to send, you can use
Encoding.ASCIIto convert it to the bytes you need.