/// <Summary>
/// Convert byte type to string
/// </Summary>
/// <Param name = "arrinput"> byte array </param>
/// <Returns> Target string </returns>
Private string bytearraytostring (byte [] arrinput)
{
Int I;
Stringbuilder soutput = new stringbuilder (arrinput. Length );
For (I = 0; I <arrinput. length; I ++)
{
Soutput. append (arrinput [I]. tostring ("X2 "));
}
// Convert the Instance value to system. String
Return soutput. tostring ();
}
/// <Summary>
/// Unpackage the received data (unpack the received byte array as a unicode string)
/// </Summary>
/// <Param name = "recbytes"> byte array </param>
/// <Returns> Unicode-encoded string </returns>
Public String dispackage (byte [] recbytes)
{
String temp = "";
Foreach (byte B in recbytes)
Temp + = B. tostring ("X2") + ""; // tostring ("X2") is the string format controller in C #
Return temp;
}
========================================================== ====================
Tostring ("X2") is the string format controller in C #
X is hexadecimal
2. It indicates that each request is a double digit.
For example, 0x0a. If there is no 2, only 0xa is output.
Assume that there are two numbers 10 and 26. Normally, the hexadecimal format displays 0xa and 0x1a, which looks untidy. To look good, you can specify "X2". The displayed result is: 0x0a, 0x1a.
Reference: http://topic.csdn.net/t/20050709/17/4133902.html
From: http://www.cnblogs.com/kuang906/articles/2301361.html