在c#中将对象转换为字节数组

CRK*_*CRK 6 c# bytearray

我想在c#中将对象值转换为字节数组.

EX:

 step 1. Input : 2200
 step 2. After converting Byte : 0898
 step 3. take first byte(08)

 Output: 08
Run Code Online (Sandbox Code Playgroud)

谢谢

Dar*_*rov 11

您可以查看GetBytes方法:

int i = 2200;
byte[] bytes = BitConverter.GetBytes(i);
Console.WriteLine(bytes[0].ToString("x"));
Console.WriteLine(bytes[1].ToString("x"));
Run Code Online (Sandbox Code Playgroud)

还要确保在第一个字节的定义中考虑了字节序.