| 1 | unit UBigInt;
|
|---|
| 2 |
|
|---|
| 3 | {$mode delphi}
|
|---|
| 4 |
|
|---|
| 5 | interface
|
|---|
| 6 |
|
|---|
| 7 | uses
|
|---|
| 8 | Classes, SysUtils;
|
|---|
| 9 |
|
|---|
| 10 | type
|
|---|
| 11 |
|
|---|
| 12 | { TBigInt }
|
|---|
| 13 |
|
|---|
| 14 | TBigInt = record
|
|---|
| 15 | Value: array of Byte;
|
|---|
| 16 | class operator Add(A, B: TBigInt): TBigInt;
|
|---|
| 17 | class operator Subtract(A, B: TBigInt): TBigInt;
|
|---|
| 18 | class operator Multiply(A, B: TBigInt): TBigInt;
|
|---|
| 19 | class operator Divide(A, B: TBigInt): TBigInt;
|
|---|
| 20 | class operator IntDivide(A, B: TBigInt): TBigInt;
|
|---|
| 21 | class operator Modulus(A, B: TBigInt): TBigInt;
|
|---|
| 22 | class operator GreaterThan(A: TBigInt; B: TBigInt): Boolean;
|
|---|
| 23 | class operator GreaterThanOrEqual(A: TBigInt; B: TBigInt): Boolean;
|
|---|
| 24 | class operator LessThan(A: TBigInt; B: TBigInt): Boolean;
|
|---|
| 25 | class operator LessThanOrEqual(A: TBigInt; B: TBigInt): Boolean;
|
|---|
| 26 | class operator Implicit(A: Integer): TBigInt;
|
|---|
| 27 | class operator Implicit(A: ShortInt): TBigInt;
|
|---|
| 28 | class operator Implicit(A: Int64): TBigInt;
|
|---|
| 29 | class operator Implicit(A: TBigInt): LongInt;
|
|---|
| 30 | class operator Implicit(A: TBigInt): Int64;
|
|---|
| 31 | class operator Equal(A: TBigInt; B: TBigInt): Boolean;
|
|---|
| 32 | end;
|
|---|
| 33 |
|
|---|
| 34 | function IntToHex(Value: TBigInt; Digits: Integer): string; overload;
|
|---|
| 35 | function IntToStr(Value: TBigInt): string; overload;
|
|---|
| 36 |
|
|---|
| 37 | implementation
|
|---|
| 38 |
|
|---|
| 39 | { TBigInt }
|
|---|
| 40 |
|
|---|
| 41 | class operator TBigInt.Add(A, B: TBigInt): TBigInt;
|
|---|
| 42 | var
|
|---|
| 43 | I: Integer;
|
|---|
| 44 | begin
|
|---|
| 45 | for I := 0 to Length(A.Value) - 1 do
|
|---|
| 46 | Result.Value[I] := A.Value[I] + B.Value[I];
|
|---|
| 47 | //Result := ;
|
|---|
| 48 | end;
|
|---|
| 49 |
|
|---|
| 50 | class operator TBigInt.Subtract(A, B: TBigInt): TBigInt;
|
|---|
| 51 | begin
|
|---|
| 52 |
|
|---|
| 53 | end;
|
|---|
| 54 |
|
|---|
| 55 | class operator TBigInt.Multiply(A, B: TBigInt): TBigInt;
|
|---|
| 56 | begin
|
|---|
| 57 |
|
|---|
| 58 | end;
|
|---|
| 59 |
|
|---|
| 60 | class operator TBigInt.Divide(A, B: TBigInt): TBigInt;
|
|---|
| 61 | begin
|
|---|
| 62 |
|
|---|
| 63 | end;
|
|---|
| 64 |
|
|---|
| 65 | class operator TBigInt.IntDivide(A, B: TBigInt): TBigInt;
|
|---|
| 66 | begin
|
|---|
| 67 |
|
|---|
| 68 | end;
|
|---|
| 69 |
|
|---|
| 70 | class operator TBigInt.Modulus(A, B: TBigInt): TBigInt;
|
|---|
| 71 | begin
|
|---|
| 72 |
|
|---|
| 73 | end;
|
|---|
| 74 |
|
|---|
| 75 | class operator TBigInt.GreaterThan(A: TBigInt; B: TBigInt): Boolean;
|
|---|
| 76 | begin
|
|---|
| 77 |
|
|---|
| 78 | end;
|
|---|
| 79 |
|
|---|
| 80 | class operator TBigInt.GreaterThanOrEqual(A: TBigInt; B: TBigInt): Boolean;
|
|---|
| 81 | begin
|
|---|
| 82 |
|
|---|
| 83 | end;
|
|---|
| 84 |
|
|---|
| 85 | class operator TBigInt.LessThan(A: TBigInt; B: TBigInt): Boolean;
|
|---|
| 86 | begin
|
|---|
| 87 |
|
|---|
| 88 | end;
|
|---|
| 89 |
|
|---|
| 90 | class operator TBigInt.LessThanOrEqual(A: TBigInt; B: TBigInt): Boolean;
|
|---|
| 91 | begin
|
|---|
| 92 |
|
|---|
| 93 | end;
|
|---|
| 94 |
|
|---|
| 95 | class operator TBigInt.Implicit(A: Integer): TBigInt;
|
|---|
| 96 | begin
|
|---|
| 97 | SetLength(Result.Value, SizeOf(Integer));
|
|---|
| 98 | Move(A, Result.Value[0], SizeOf(Integer));
|
|---|
| 99 | end;
|
|---|
| 100 |
|
|---|
| 101 | class operator TBigInt.Implicit(A: ShortInt): TBigInt;
|
|---|
| 102 | begin
|
|---|
| 103 | SetLength(Result.Value, SizeOf(ShortInt));
|
|---|
| 104 | Move(A, Result.Value[0], SizeOf(ShortInt));
|
|---|
| 105 | end;
|
|---|
| 106 |
|
|---|
| 107 | class operator TBigInt.Implicit(A: Int64): TBigInt;
|
|---|
| 108 | begin
|
|---|
| 109 | SetLength(Result.Value, SizeOf(Int64));
|
|---|
| 110 | Move(A, Result.Value[0], SizeOf(Int64));
|
|---|
| 111 | end;
|
|---|
| 112 |
|
|---|
| 113 | class operator TBigInt.Implicit(A: TBigInt): LongInt;
|
|---|
| 114 | begin
|
|---|
| 115 | Move(A.Value[0], A, SizeOf(LongInt));
|
|---|
| 116 | end;
|
|---|
| 117 |
|
|---|
| 118 | class operator TBigInt.Implicit(A: TBigInt): Int64;
|
|---|
| 119 | begin
|
|---|
| 120 | Move(A.Value[0], A, SizeOf(Int64));
|
|---|
| 121 | end;
|
|---|
| 122 |
|
|---|
| 123 | class operator TBigInt.Equal(A: TBigInt; B: TBigInt): Boolean;
|
|---|
| 124 | begin
|
|---|
| 125 | Result := (Length(A.Value) = Length(B.Value)) and
|
|---|
| 126 | CompareMem(Addr(A.Value[0]), Addr(A.Value[0]), Length(A.Value));
|
|---|
| 127 | end;
|
|---|
| 128 |
|
|---|
| 129 | function IntToHex(Value: TBigInt; Digits: Integer): string;
|
|---|
| 130 | begin
|
|---|
| 131 |
|
|---|
| 132 | end;
|
|---|
| 133 |
|
|---|
| 134 | function IntToStr(Value: TBigInt): string;
|
|---|
| 135 | begin
|
|---|
| 136 |
|
|---|
| 137 | end;
|
|---|
| 138 |
|
|---|
| 139 | end.
|
|---|
| 140 |
|
|---|