Hello,
I'm having a problem with array and Byte type.
I've got two arrays of bytes:
static Array^ samples = Array::CreateInstance(System::Byte::typeid,100);
static Array^ fake_samples = Array::CreateInstance(System::Byte::typeid,100);
Then two functions (methods?).
This one converts number in U2 code to integer.
System::Byte ConvertFromU2(System::Byte u2)
{
System::Byte result;
if ((u2 & 0x80) == 0 )
{
result = 1.0 * u2;
}
else
{
u2 = u2 ^ 0xFF;
u2 = u2 + 1;
result = -1.0 * u2;
}
return result;
}
This one puts some numbers in an array 'fake_samples', then takes numbers from an 'fake_samples' and stores them in an array 'sampes':
void CollectSamples(void)
{
for (int i=25; i<100; i++)
{
fake_samples->SetValue(0x00, i);
}
for (int i=0; i<100; i++)
{
System::Byte one_byte=(Convert::ToByte(fake_samples->GetValue(i)));
System::Byte converted_byte;
converted_byte = ConvertFromU2(one_byte);
samples->SetValue(converted_byte, i);
}
}
This is done in such a complicated way due to some future plans concerning this program.
The code compiles, but when running I got an exception in line:
fake_samples->SetValue(0x00, i);
Exception:
Cannot widen from source type to target type either because the source type is a not a primitive type or the conversion cannot be accomplished.
I don't know what to do :( Please, help!