internal static void DivByTwo(this RawNum num) { UInt32 leadingBit = 0; for (int i = num.Size - 1; i >= 0; i--) { UInt32 bitVal = num.Digits[i]; num.Digits[i] = (leadingBit << 15) | (bitVal >> 1); leadingBit = bitVal & 1; } num.RemoveLeadingZeros(); }
internal static void Dec(this RawNum num) { const UInt32 leadingBit = (1 << 16); UInt32 z = 1; for (int i = 0; i < num.Size && z > 0; i++) { UInt32 sub = (leadingBit | num.Digits[i]) - z; num.Digits[i] = sub & UInt16.MaxValue; z = (~sub & leadingBit) >> 16; } num.RemoveLeadingZeros(); }