I have a small snippet of code that I have written, I am a bit unsure if sign extension has been properly implemented here
Essentially
I have an array of char*
data that contains values in bytes
Now I wish to construct a 16 bit (2 byte) value from this data array
I do this by getting the byte @ address 0 and address 1 and combining them.
This part is working and I am sure of it
Now this is a 16 bit value, which I aim to store in my signed integer array. And obviously integers are 32 bits (4 bytes) thus will need to be padded with an additional 16 bits
Now my question is this
void store_data(unsigned char* data){
int param1 = 5;
int param2 = 6;
int address = array_of_ints[param2] + 50;
int value = memory[address] | (memory[address+1] << 8);
int32_t sign = value;
array_of_ints[param1] = sign;
}
Has my code been properly sign extending the value from memory
Since I am storing it as a signed 32_int I would not need to pad it with an additional 16 bits right?