Firmado corto a byte en c ++

Estoy intentando convertir un número HEX en un corto (2 bytes) usando C ++ todo está bien, excepto por una cosa ... conversión firmada de corto a byte (última prueba)

Encontré esta pregunta y no pude realmente beneficiarme de ella:Conversión de bytes portátil firmado / sin firmar, C ++

Aquí están mis pruebas:

<code>// test 1 - positive B2Short (success)
byte *b = new byte[2];
b[0] = 0x10; //low byte
b[1] = 0x00; //heigh byte

signed short test = 0;
test = ByteToShort(b);
cout << test << endl;

// test 2 - negative B2Short (success)
b[0] = 0xF0; //low byte
b[1] = 0xFF; //heigh byte

test = 0;
test = ByteToShort(b);
cout << test << endl;

// test 3 - positive Short2B (success)
signed short n = 11;
ShortToByte(n, b);
test = ByteToShort(b);  // for display to see if it worked
cout << test << endl;

// test 4 - negative Short2B (FAIL!)
n = -11;
ShortToByte(n, b);
test = ByteToShort(b);  // for display to see if it worked
cout << test << endl;
</code>

funciones utilizadas:

<code>signed short ByteToShort(byte* bytes){

    signed short result = 0;
    result = (result<<8) + bytes[1]; // heigh byte
    result = (result<<8) + bytes[0]; // low byte
    return result;
}

void ShortToByte(signed short num, byte* bytes){

    bytes[1] = num & 0xFF00; // heigh byte
    bytes[0] = num & 0x00FF; // low byte
}
</code>

salidas:

<code>16
-16
11
245
</code>

Respuestas a la pregunta(3)

Su respuesta a la pregunta