У меня есть байтовый массив , полученный из программы Cpp.
arr[0..3] // a real32,
arr[4] // a uint8,
Как я могу интерпретировать arr[4]
как int
?
(uint)arr[4] // Err: can't implicitly convert string to int.
BitConverter.ToUint16(arr[4]) // Err: Invalid argument.
buff[0+4] as int // Err: must be reference or nullable type
Нужно ли обнулять последовательный байт, чтобы интерпретировать его как UInt16
?
Хорошо, здесь путаница. Изначально я определил свой класс.
byte[] buff;
buff = getSerialBuffer();
public class Reading{
public string scale_id;
public string measure;
public int measure_revised;
public float wt;
}
rd = new Reading();
// !! here is the confusion... !!
// Err: Can't implicitly convert 'string' to 'int'
rd.measure = string.Format("{0}", buff[0 + 4]);
// then I thought, maybe I should convert buff[4] to int first ?
// I throw all forms of conversion here, non worked.
// but, later it turns out:
rd.measure_revised = buff[0+4]; // just ok.
Так что, в принципе, я не понимаю, почему это происходит
rd.measure = string.Format("{0}", buff[0 + 4]);
//Err: Can't implicitly convert 'string' to 'int'
Если бафф [4] - это байт, а байт - uint8, что это значит под can't implicitly convert string to int
? ... Это меня смущает.