I have the following code, which does the following:
Reads from the packet from UDP (SNMP) into an array, check if this number is > 127, if yes then '&' this with 127, now pad it with leading zero's to make it 7 bits in total. Combine it with result. Now check the next one in the packet and repeat the above. It works for if 3 numbers > 127. Can this code be optimized check for unlimited throughout the length of the array
Please do let me know if you require any further information.
Thank you.
int[] obj = new int[Objectlength];
string result = string.Empty;
for (int cnt = 0; cnt < Objectlength; cnt++)
{
obj[cnt] = Convert.ToInt16(packet[objectstart]);
objectstart++;
if (obj[cnt] >127)
{
int brush = 127;
int bin = obj[cnt] & brush;
string binR1 = Convert.ToString(bin, 2).PadLeft(7, '0');
result = result + binR1;
cnt++;
if ((packet[objectstart] > 127) | (packet[objectstart] < 127))
{
Console.WriteLine(packet[objectstart]);
int bin1 = packet[objectstart] & brush ;
binR1 = Convert.ToString(bin1, 2).PadLeft(7, '0');
result = result + binR1;
obj[cnt] = Convert.ToInt16(packet[objectstart]);
cnt++;
objectstart++;
if ((packet[objectstart] > 127) | (packet[objectstart] < 127))
{
Console.WriteLine(packet[objectstart]);
int bin2 = packet[objectstart] & brush;
binR1 = Convert.ToString(bin2, 2).PadLeft(7, '0');
result = result + binR1;
obj[cnt] = Convert.ToInt16(packet[objectstart]);
objectstart++;
}
}
}
}