Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef BigIntegerBaseH
00032 #define BigIntegerBaseH
00033
00034 #include <zeusbase/System/ZValueType.hpp>
00035
00036 BEGIN_NAMESPACE_Zeus
00037
00038
00041
00042 zeusbase_class TBigIntegerBase
00043 {
00044 public:
00045
00046 static void add(const Uint8* pui8Data1,
00047 Int iSize1,
00048 Uint8* pui8Data2,
00049 Int iSize2);
00050 static bool isNegative(const Uint8* pui8Data, Int iSize);
00051 static bool isZero(const Uint8* pui8Data, Int iSize);
00052 static bool isZeroEx(const Uint8* pui8Data, Int& rLastByteChecked);
00053 static void multiply(const Uint8* pui8Data1,
00054 Int iSize1,
00055 const Uint8* pui8Data2,
00056 Int iSize2,
00057 Uint8* pui8Result);
00058 static void negate(Uint8* pui8Data, Int iSize);
00059 static void shiftLeft(Uint8* pui8Data, Int iSize, Int iShift);
00060 static void shiftLeft8Bit(Uint8* pui8Data, Int iSize, Int iShift);
00061 static void shiftRight(Uint8* pui8Data, Int iSize, Int iShift);
00062 static void shiftRight8Bit(Uint8* pui8Data, Int iSize, Int iShift);
00063
00064 protected:
00065
00066 private:
00067 };
00068
00069
00070
00078
00079 inline bool TBigIntegerBase::isNegative(const Uint8* pui8Data, Int iSize)
00080 {
00081 return (pui8Data[iSize-1] & 0x80) != 0;
00082 }
00083
00084
00091
00092 inline bool TBigIntegerBase::isZero(const Uint8* pui8Data, Int iSize)
00093 {
00094 bool bRetval = true;
00095
00096 register Int i;
00097 for (i = 0; bRetval && i < iSize; i++)
00098 {
00099 bRetval = (pui8Data[i] == 0x00);
00100 }
00101
00102 return bRetval;
00103 }
00104
00105
00113
00114 inline bool TBigIntegerBase::isZeroEx(const Uint8* pui8Data, Int& rLastByteChecked)
00115 {
00116 bool bRetval = true;
00117
00118 register Int i;
00119 for (i = rLastByteChecked; bRetval && i >= 0; i--)
00120 {
00121 bRetval = (pui8Data[i] == 0x00);
00122 }
00123 rLastByteChecked = i;
00124 rLastByteChecked++;
00125
00126 return bRetval;
00127 }
00128
00129
00130
00136
00137 inline void TBigIntegerBase::negate(Uint8* pui8Data, Int iSize)
00138 {
00139 register Int i;
00140 for (i = 0; i < iSize; i++)
00141 {
00142 pui8Data[i] = (Uint8)(~pui8Data[i]);
00143 }
00144
00145 Uint8 ui8Data = 1;
00146 TBigIntegerBase::add(&ui8Data, 1, pui8Data, iSize);
00147 }
00148
00149
00155
00156 inline void TBigIntegerBase::shiftLeft8Bit(Uint8* pui8Data, Int iSize, Int iShift)
00157 {
00158 register Int i;
00159 register Uint8 ui8Overflow;
00160
00161 pui8Data[iSize-1] <<= iShift;
00162
00163 for(i = iSize-2; i >= 0; i--)
00164 {
00165 ui8Overflow = (Uint8)(pui8Data[i] >> (8 - iShift));
00166 pui8Data[i+1] |= ui8Overflow;
00167 pui8Data[i] <<= iShift;
00168 }
00169 }
00170
00171
00177
00178 inline void TBigIntegerBase::shiftRight8Bit(Uint8* pui8Data, Int iSize, Int iShift)
00179 {
00180 register Int i;
00181 register Uint8 ui8Overflow;
00182
00183 pui8Data[0] >>= iShift;
00184
00185 for(i = 1; i < iSize; i++)
00186 {
00187 ui8Overflow = (Uint8)(pui8Data[i] << (8 - iShift));
00188 pui8Data[i-1] |= ui8Overflow;
00189 pui8Data[i] >>= iShift;
00190 }
00191 }
00192
00193
00194 END_NAMESPACE_Zeus
00195
00196 #endif