private static UInt16 ShiftArithmetic(ShiftDirectionFunc shiftDirectionFunc, UInt16 ui16Val) { // 算術シフトでは、符号ビットの値はそのまま変化しない。 UInt16 signBit = UInt16Utils.GetBit(ui16Val, UInt16Utils.MSB); UInt16 shiftedValue = ShiftLogical(shiftDirectionFunc, ui16Val); UInt16 shiftedSignedValue = UInt16Utils.SetBit(shiftedValue, UInt16Utils.MSB, signBit); return(shiftedSignedValue); }
private static Word DoShift( ShiftTypeFunc shiftTypeFunc, ShiftDirectionFunc shiftDirectionFunc, Int32 shiftedOutBitPos, Word word1, Word word2, out UInt16 lastShiftedOutBit) { UInt16 shiftedValue = word1.GetAsUnsigned(); UInt16 shiftCount = word2.GetAsUnsigned(); // BitSize (= 16) 回以上シフトしても、結果は変わらない。 shiftCount = Math.Min((UInt16)UInt16Utils.BitSize, shiftCount); lastShiftedOutBit = 0; for (UInt16 shiftIndex = 0; shiftIndex < shiftCount; ++shiftIndex) { lastShiftedOutBit = UInt16Utils.GetBit(shiftedValue, shiftedOutBitPos); shiftedValue = shiftTypeFunc(shiftDirectionFunc, shiftedValue); } return(new Word(shiftedValue)); }
private static UInt16 ShiftLogical(ShiftDirectionFunc shiftDirectionFunc, UInt16 ui16Val) { UInt16 shiftedValue = shiftDirectionFunc(ui16Val); return(shiftedValue); }