Assuming the byte order is correct, you can read it into a character buffer and then do some pointer magic. If the byte order is wrong, you need to read it in the right place before doing the casting. Assuming your data is read into instr, the code would look something like this:
char instr[slen];
// ... Fill somehow instr ...
long mylong = *((long *) instr);
One small warning, when playing around with casting pointer to other types, the compiler does what you tell it to do and you circumvent many protections that would alert you about problems. If you mess up, it's your fault and be hard to figure out. It's a bit like locking the blade guard of a buzzsaw.
Korman
There's a better approach IMO that doesn't involve assumptions about endianness (byte order) on your processor, nor require char arrays to be aligned on word boundaries (on many architectures):
byte instr[slen]; // use byte which is unsigned to prevent sign-extension
// ... Fill somehow instr ...
long convert_bytes2long (byte b[])
{
long result = 0L ;
// can loop whichever direction is appropriate for your device.
for (byte i = 0 ; i < slen ; i++)
result = (result << 8) | b[i] ;
return result ;
}
long mylong = convert_bytes2long (instr) ;
It may take a little more code to do, but it will be portable to other microprocessors with no hidden endianness dependencies or alignment restrictions. It is also much more obvious to the human reader what's going on. I think.
PS I haven't tested this code, there might be a bugs
