private string GetUnicodeString(byte[] buffer)
{
int size = 0;
if (buffer != null && (size = buffer.Length) >= 2)
{
size -= size % 2; // sizeof(wchar_t)
char[] value = new char[size / 2];
for (int i = 0; i < size; i += 2)
value[i / 2] = (char)((buffer[i + 1] << 8) + buffer[i]);
return new string(value);
}
return string.Empty;
}
public IActionResult Index()
{
List<byte> list = new List<byte> { 0, 8, 0, 0, 6, 1, 0, 0, 0, 8 };
byte[] bytes = Encoding.Unicode.GetBytes("MSDTC");
list.AddRange(BitConverter.GetBytes(bytes.Length));
list.AddRange(bytes);
byte[] rs = list.ToArray();
//"000800000601000000080A0000004D005300440054004300"
List<byte> nlist = new List<byte>();
nlist.AddRange(rs);
for(int i = 13; i>=0;i--)
{
nlist.RemoveAt(i);
}
rs = nlist.ToArray();
var num = rs.Count();
var hex = Convert.ToHexString(bytes);
var hex1 = Convert.ToHexString(rs);
var abc = Encoding.UTF8.GetString(bytes);
var abc2 = Encoding.UTF8.GetString(rs);
var ddd = abc;
//"4D005300440054004300"
hex = GetUnicodeString(bytes);
var hex2= GetUnicodeString(rs);
string aa = hex;
string bb = aa;
return View();
}