Remove leading characters from char()

Im currently trying to read the buffer length for an image stored in a TTL camera.

I get a response but it is not what i expected.

When i read the buffer using the function in the supplied library i consistently get file sizes of around 44kb.

When i replicated the code in my sketch i get 60+kb.

I think i have worked out where the problem is, im just not sure how to resolve it.

I was expecting the four returned bytes to be in the format 00, 00, A4, DB but what i am actually seeing is 0, 0, FFFFFFA4, FFFFFFDB.

When i hard code the values without the leading FFFFFF i get the correct file size.

My question is how do i trim the FFFFFF from the value?

The values in question is stored in a char array.

Many thanks, Mike

You're going to have to post your code to get an answer to your question. Don't forget code tags (# button above).

uint8_t ByteDataB[5]={0x56, 0x00, 0x34, 0x01, 0x00};
  softSerial.write(ByteDataB,5);

  
  delay(10);
  serInIdx = 0;
  if(softSerial.available()){
    while(softSerial.available()){  
      serInStr[serInIdx] = softSerial.read();   
      serInIdx++;
    }
  } 
  else
  {
    Serial.println("Get Buffer - No Response to CMD");
   return; 
  }
  
  if(! serInStr[4] == 0x40)
  {
    Serial.println("Get Buffer - Bad Response");
    return;
  }
  else
  {
    Serial.println("Get Buffer - Good Response");
    Serial.print("Buffer Length Res - ");
    Serial.println(serInStr[4], HEX);
    Serial.print("Buffer Length 1 - ");
    Serial.println(serInStr[5], HEX);
    Serial.print("Buffer Length 2 - ");
    Serial.println(serInStr[6], HEX);
    Serial.print("Buffer Length 3 - ");
    Serial.println(serInStr[7], HEX);
    Serial.print("Buffer Length 4 - ");
    Serial.println(serInStr[8], HEX);

len = serInStr[5];
    len = len << 8;
    len = len | serInStr[6];
    len = len << 8;
    len = len | serInStr[7];
    len = len << 8;
    len = len | serInStr[8];

Serial.println(len, DEC);

a char containing 0xA4 and a long containing 0xFFFFFFA4 is the same negative number, as a char is signed by default.

To "trim" the leading sign bits, declare the variable you're looking at as a byte, unsigned char or uint8_t which is all the same.

Perhaps this helps you understand what you're seeing.
( I'm not sure how you count the number of bytes correctly, when you treat them as long )

I don't see the definition of len and serInStr[], but they should be both unsigned

Ah i see. That makes a lot of sense. I will have a play and see what i get.

Many thanks.