У меня есть код, который я хочу преобразовать:
Код: Выделить всё
void someFunction(short a, short b)
{
int x = (int)((int)a * (int)b);
}
Код: Выделить всё
public static short[] multiplyShorts(short a, short b)
{
short aHigh = (short)((a >> 8) & 0xFF);
short aLow = (short)(a & 0xFF);
short bHigh = (short)((b >> 8) & 0xFF);
short bLow = (short)(b & 0xFF);
short lowLow = (short)(aLow * bLow);
short highLow = (short)(aHigh * bLow);
short lowHigh = (short)(aLow * bHigh);
short highHigh = (short)(aHigh * bHigh);
short[] result = new short[2];
result[1] = (short)(lowLow & 0xFF);
short carry = (short)((lowLow >> 8) & 0xFF);
short middle = (short)(highLow + lowHigh + carry);
result[1] |= (short)((middle & 0xFF) > 8) & 0xFF);
result[0] = (short)(result[0] + highHigh);
return result;
}
Код: Выделить всё
result[0] = 0xFFFE = 0b11111111_11111110
result[1] = 0x0001 = 0b00000000_00000001
Код: Выделить всё
result[0] = 0xFEFE = 0b11111110_11111110 //Spot the difference on this line
result[1] = 0x0001 = 0b00000000_00000001
Подробнее здесь: https://stackoverflow.com/questions/790 ... ply-shorts
Мобильная версия