Convert byte array to int

前端 未结 4 1128
既然无缘
既然无缘 2021-01-04 18:03

I am trying to do some conversion in C#, and I am not sure how to do this:

private int byteArray2Int(byte[] bytes)
{
    // bytes = new byte[] {0x01, 0x03, 0         


        
4条回答
  •  死守一世寂寞
    2021-01-04 18:33

    1. this is correct, but you're missing, that Convert.ToInt32 'wants' 32 bits (32/8 = 4 bytes) of information to make a conversion, so you cannot convert just One byte: `new byte [] {0x32}

    2. absolutely the the same trouble you have. and do not forget about the encoding you use: from encoding to encoding you have 'different byte count per symbol'

提交回复
热议问题