Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions

zeus::TBigInteger< N > Class Template Reference

#include <BigInteger.hpp>

List of all members.

Public Member Functions

 TBigInteger ()
 TBigInteger (const TBigInteger< N > &rValue)
 TBigInteger (const IByteArray &rArray, Int iFromIndex=0)
 TBigInteger (const Uint8 *pui8Array, Int iSize)
 TBigInteger (int iValue)
 TBigInteger (unsigned int uiValue)
 TBigInteger (Uint32 ui32Value)
 TBigInteger (Int32 i32Value)
 TBigInteger (Uint64 ui64Value)
 TBigInteger (Int64 i64Value)
Int getBitSize () const
Int getByteSize () const
Int getBitLength () const
bool isNegative () const
bool isZero () const
TBigInteger< N > & add (const TBigInteger< N > &rParam)
TBigInteger< N > & add (int iParam)
TBigInteger< N > & add (unsigned int uiParam)
void assign (const TBigInteger< N > &rParam)
void clear ()
Int compareTo (const TBigInteger< N > &rParam) const
TBigInteger< N > & divide (const TBigInteger< N > &rParam)
TBigInteger< N > & divideExt (const TBigInteger< N > &rParam, TBigInteger< N > &rModulo)
TBigInteger< N > getNegated () const
TBigInteger< N > getLeftShifted (Int iShift) const
TBigInteger< N > getRightShifted (Int iShift) const
TBigInteger< N > getSubtracted (const TBigInteger< N > &rParam) const
TBigInteger< N > & mod (const TBigInteger< N > &rParam)
TBigInteger< N > & modpow (const TBigInteger< N > &rExp, const TBigInteger< N > &rMod)
TBigInteger< N > & negate ()
void shiftLeft (Int iShift)
void shiftRight (Int iShift)
TBigInteger< N > & subtract (const TBigInteger< N > &rParam)
TBigInteger< N > & multiply (const TBigInteger< N > &rParam)
void toByteArray (IByteArray &rData, Int iSize=N) const
void appendToByteArray (IByteArray &rData, Int iSize=N) const
TBigInteger< N > & operator= (const TBigInteger< N > &rParam)
bool operator== (const TBigInteger< N > &rParam) const
bool operator!= (const TBigInteger< N > &rParam) const
bool operator< (const TBigInteger< N > &rParam) const
bool operator> (const TBigInteger< N > &rParam) const
TBigInteger< N > operator+ (const TBigInteger< N > &rParam)
TBigInteger< N > operator- (const TBigInteger< N > &rParam) const
TBigInteger< N > operator- ()
TBigInteger< N > operator* (const TBigInteger< N > &rParam) const
TBigInteger< N > operator/ (const TBigInteger< N > &rParam) const
TBigInteger< N > operator% (const TBigInteger< N > &rParam) const

Static Public Member Functions

static TBigInteger< N > createFromHex (const TString &rHexString)

Protected Member Functions

void assign32bit (Uint32 ui64Value, bool bNegative)
void assign64bit (Uint64 ui64Value, bool bNegative)

Static Protected Member Functions

static void divide_internal (const Uint8 *pui8Divisor, Uint8 *pui8Base, Uint8 *pui8Modulo)
static void mod_internal (const Uint8 *pui8Divisor, const Uint8 *pui8NegDivisor, Uint8 *pui8Modulo)
static void multiply_internal (const Uint8 *pui8Data1, Uint8 *pui8Data2)
static void multiply_karatsuba (const Uint8 *pui8Data1, const Uint8 *pui8Data2, Uint8 *pui8Result)
static Int compareTo_internal (const Uint8 *pui8Data1, const Uint8 *pui8Data2)
static Int compareTo_positive (const Uint8 *pui8Data1, const Uint8 *pui8Data2, Int iSize)
static Int getLastSignPos (const Uint8 *pui8Data, Int iSize)

Detailed Description

template<int N>
class zeus::TBigInteger< N >

implements big integers with bit size >= 64bits


Constructor & Destructor Documentation

template<int N>
zeus::TBigInteger< N >::TBigInteger (  ) [inline]

creates an empty big number (zero)

template<int N>
zeus::TBigInteger< N >::TBigInteger ( const TBigInteger< N > &  rValue ) [inline]

copy constructor

Parameters:
rValue: number ro copy
template<int N>
zeus::TBigInteger< N >::TBigInteger ( const IByteArray rArray,
Int  iFromIndex = 0 
) [inline]

creates a big number out of a byte array

Parameters:
rArray: array object
iFromIndex: index to get the number from the array
template<int N>
zeus::TBigInteger< N >::TBigInteger ( const Uint8 pui8Array,
Int  iSize 
) [inline]

creates a big number out of a byte array

Parameters:
rArray: array object
iFromIndex: index to get the number from the array
template<int N>
zeus::TBigInteger< N >::TBigInteger ( int  iValue ) [inline]

creates a big number out of a integer (signed)

Parameters:
iValue: simple integer valaue
template<int N>
zeus::TBigInteger< N >::TBigInteger ( unsigned int  uiValue ) [inline]

creates a big number out of a integer (unsigned signed)

Parameters:
uiValue: simple unsigned integer valaue
template<int N>
zeus::TBigInteger< N >::TBigInteger ( Uint32  ui32Value ) [inline]

creates a big number out of a uint32

Parameters:
ulValue: simple unsigned integer valaue
template<int N>
zeus::TBigInteger< N >::TBigInteger ( Int32  i32Value ) [inline]

creates a big number out of a int32

Parameters:
lValue: simple integer valaue
template<int N>
zeus::TBigInteger< N >::TBigInteger ( Uint64  ui64Value ) [inline]

creates a big number out of a uint64

Parameters:
uldValue: simple unsigned integer valaue
template<int N>
zeus::TBigInteger< N >::TBigInteger ( Int64  i64Value ) [inline]

creates a big number out of a int64

Parameters:
ldValue: simple integer valaue

Member Function Documentation

template<int N>
TBigInteger<N>& zeus::TBigInteger< N >::add ( const TBigInteger< N > &  rParam ) [inline]

adds an other big number to this number

Parameters:
rParam: big number to add
Returns:
result
template<int N>
TBigInteger<N>& zeus::TBigInteger< N >::add ( int  iParam ) [inline]

adds a simple integer number to this big number

Parameters:
iParam: simple number to add
Returns:
result
template<int N>
TBigInteger<N>& zeus::TBigInteger< N >::add ( unsigned int  uiParam ) [inline]

adds a simple unsigned integer number to this big number

Parameters:
uiParam: simple number to add
Returns:
result
template<int N>
void zeus::TBigInteger< N >::appendToByteArray ( IByteArray rData,
Int  iSize = N 
) const [inline]

Converts the big integer into a byte array and appends it at the end of an existing array

Parameters:
rData: [OUT] array
iSize: [IN] size to add
template<int N>
void zeus::TBigInteger< N >::assign ( const TBigInteger< N > &  rParam ) [inline]

assigns a new big integer value to this container

Parameters:
rParam: value to assign
template<int N>
void zeus::TBigInteger< N >::assign32bit ( Uint32  ui32Value,
bool  bNegative 
) [protected]

assigns a 32bit value

Parameters:
ui32Value: value to assign
bNegative: represents a negative value = true
template<int N>
void zeus::TBigInteger< N >::assign64bit ( Uint64  ui64Value,
bool  bNegative 
) [protected]

assigns a int64 value

Parameters:
uldValue: value to assign
bNegative: represents a negative value = true
template<int N>
void zeus::TBigInteger< N >::clear (  ) [inline]

clears the big number. The big number is zero after this operation

template<int N>
Int zeus::TBigInteger< N >::compareTo ( const TBigInteger< N > &  rParam ) const [inline]

compares two big integers and returns 0 if they are equal, < 0 if the this is smaller or > 0 is the this is bigger

Parameters:
rParam: value to check
Return values:
<0 : this < rParam
0: this == rParam > 0 : this > rParam
template<int N>
Int zeus::TBigInteger< N >::compareTo_internal ( const Uint8 pui8Data1,
const Uint8 pui8Data2 
) [static, protected]

compares two big integers and returns 0 if they are equal, < 0 if the this is smaller or > 0 is the this is bigger

Parameters:
rParam: value to check
Return values:
<0 : pui8Data1 < pui8Data2
0: pui8Data1 == pui8Data2 > 0 : pui8Data1 > pui8Data2
template<int N>
Int zeus::TBigInteger< N >::compareTo_positive ( const Uint8 pui8Data1,
const Uint8 pui8Data2,
Int  iSize 
) [static, protected]

compares two big integers and returns 0 if they are equal, < 0 if the this is smaller or > 0 is the this is bigger. In contrast to compareTo_internal only positive numbers are checked

Parameters:
pui8Data1: value 1 to check
pui8Data2: value 2 to check
iSize: size of the smallest value
Return values:
<0 : pui8Data1 < pui8Data2
0: pui8Data1 == pui8Data2 > 0 : pui8Data1 > pui8Data2
template<int N>
static TBigInteger<N> zeus::TBigInteger< N >::createFromHex ( const TString rHexString ) [inline, static]

Creates a new big integer from a hex based string

Parameters:
rHexString: string containing hex number
Returns:
new big integer
template<int N>
TBigInteger<N>& zeus::TBigInteger< N >::divide ( const TBigInteger< N > &  rParam ) [inline]

divides this big number by a divisors

Parameters:
rParam: divisor
Returns:
result
template<int N>
void zeus::TBigInteger< N >::divide_internal ( const Uint8 pui8Divisor,
Uint8 pui8Base,
Uint8 pui8Modulo 
) [static, protected]

divides two big integers

Parameters:
pui8Divisor: [IN] divisor
pui8Base: [INOUT] base and result of the division
pui8Modulo: [OUT] modulo of the division
template<int N>
TBigInteger<N>& zeus::TBigInteger< N >::divideExt ( const TBigInteger< N > &  rParam,
TBigInteger< N > &  rModulo 
) [inline]

divides this big number by a divisors

Parameters:
rParam: divisor
Returns:
result
template<int N>
Int zeus::TBigInteger< N >::getBitLength (  ) const [inline]

in contrast to getBitSize() this returns the effective length in bits of the number

template<int N>
Int zeus::TBigInteger< N >::getBitSize (  ) const [inline]

returns the size of the number memory in bits TBigInteger<64> will return 512

template<int N>
Int zeus::TBigInteger< N >::getByteSize (  ) const [inline]

returns the size of the number memory in bytes TBigInteger<64> will return 64

template<int N>
static Int zeus::TBigInteger< N >::getLastSignPos ( const Uint8 pui8Data,
Int  iSize 
) [inline, static, protected]

returns the position of the last sign

template<int N>
TBigInteger<N> zeus::TBigInteger< N >::getLeftShifted ( Int  iShift ) const [inline]

returns the value shiftet by iShift. The content of this big value is not changed. Use shiftLeft() to directly shift a value.

Parameters:
iShift: shift in bits
Returns:
shiftet value
template<int N>
TBigInteger<N> zeus::TBigInteger< N >::getNegated (  ) const [inline]

Returns the negation of this value. The content of this big value is not changed. Use negate() to directly negate a value.

Returns:
negated value
template<int N>
TBigInteger<N> zeus::TBigInteger< N >::getRightShifted ( Int  iShift ) const [inline]

returns the value shiftet by iShift. The content of this big value is not changed. Use shiftLeft() to directly shift a value.

Parameters:
iShift: shift in bits
Returns:
shiftet value
template<int N>
TBigInteger<N> zeus::TBigInteger< N >::getSubtracted ( const TBigInteger< N > &  rParam ) const [inline]

returns the subtracted value. The content of this big value is not changed. Use substract() to directly substract a value.

Parameters:
rParam: value to subtract
Returns:
difference
template<int N>
bool zeus::TBigInteger< N >::isNegative (  ) const [inline]

Checks if the number is negative

Return values:
true: number is negative
false,:number is not negative (zero or positive)
template<int N>
bool zeus::TBigInteger< N >::isZero (  ) const [inline]

returns true if the number is zero

Return values:
true: number is zero
false,:number is non zero
template<int N>
TBigInteger<N>& zeus::TBigInteger< N >::mod ( const TBigInteger< N > &  rParam ) [inline]

Applies the modulus operation to this value.

Parameters:
rParam: modulus
Returns:
this
template<int N>
void zeus::TBigInteger< N >::mod_internal ( const Uint8 pui8Divisor,
const Uint8 pui8NegDivisor,
Uint8 pui8Modulo 
) [static, protected]

implements a fast modulo method. In contrast to the divide_internal, only the modulus relevant implementation is kept.

Parameters:
pui8Divisor: [IN] divisor
pui8NegDivisor: [IN] inverse divisor
pui8Modulo: [INOUT] inputs the base and returns the modulo of the division
template<int N>
TBigInteger<N>& zeus::TBigInteger< N >::modpow ( const TBigInteger< N > &  rExp,
const TBigInteger< N > &  rMod 
) [inline]

returns the modulus of an exponential term. this = (this ^ exp) mod n. Fast and simple algorithm was found at http://en.wikipedia.org/wiki/Modular_exponentiation

Parameters:
rExp: exponent
rMod: modulo
Returns:
this
template<int N>
TBigInteger<N>& zeus::TBigInteger< N >::multiply ( const TBigInteger< N > &  rParam ) [inline]

multiplies two big numbers together

Parameters:
rParam: value to multiply
Returns:
this
template<int N>
void zeus::TBigInteger< N >::multiply_internal ( const Uint8 pui8Data1,
Uint8 pui8Data2 
) [static, protected]

internal method to multiply two big numbers together

Parameters:
pui8Data1: [IN] first number of size N
pui8Data2: [INOUT] second number and result of size N
template<int N>
void zeus::TBigInteger< N >::multiply_karatsuba ( const Uint8 pui8Data1,
const Uint8 pui8Data2,
Uint8 pui8Result 
) [static, protected]

multiplies two big numbers together using the karatsuba algorithm. This algorithm is more efficient than the conventional multiplications O(n^1.585) instead of O(n^2). Since for smaller numbers the conventional multiplication is as fast we use the karatsuba for bit length over 3200bits (400*8).

Note:
Link http://de.wikipedia.org/wiki/Karatsuba-Algorithmus
Parameters:
pui8Data1: [IN] first number of size N
pui8Data2: [IN] second number of size N
pui8Result: [OUT] result of size N*N. The result buffer must be at zero before starting
template<int N>
TBigInteger<N>& zeus::TBigInteger< N >::negate (  ) [inline]

Negates the big integer value

Returns:
this
template<int N>
bool zeus::TBigInteger< N >::operator!= ( const TBigInteger< N > &  rParam ) const [inline]

checks if two big numbers are unequal

Parameters:
rParam: big number to check
Return values:
true: are not equal
false,:are equal
template<int N>
TBigInteger<N> zeus::TBigInteger< N >::operator% ( const TBigInteger< N > &  rParam ) const [inline]

modulo of two values

template<int N>
TBigInteger<N> zeus::TBigInteger< N >::operator* ( const TBigInteger< N > &  rParam ) const [inline]

Multiplies two values

template<int N>
TBigInteger<N> zeus::TBigInteger< N >::operator+ ( const TBigInteger< N > &  rParam ) [inline]

Adds two values

template<int N>
TBigInteger<N> zeus::TBigInteger< N >::operator- (  ) [inline]

unary negative operator

template<int N>
TBigInteger<N> zeus::TBigInteger< N >::operator- ( const TBigInteger< N > &  rParam ) const [inline]

subtracts two values

template<int N>
TBigInteger<N> zeus::TBigInteger< N >::operator/ ( const TBigInteger< N > &  rParam ) const [inline]

divides two values

template<int N>
bool zeus::TBigInteger< N >::operator< ( const TBigInteger< N > &  rParam ) const [inline]

checks if the given integer is bigger

Parameters:
rParam: big number to check
Return values:
true: rParam is bigger
false,:rParam is smaller
template<int N>
TBigInteger<N>& zeus::TBigInteger< N >::operator= ( const TBigInteger< N > &  rParam ) [inline]

assign a new big integer to this value

template<int N>
bool zeus::TBigInteger< N >::operator== ( const TBigInteger< N > &  rParam ) const [inline]

checks if two big numbers are equal

Parameters:
rParam: big number to check
Return values:
true: are equal
false,:not equal
template<int N>
bool zeus::TBigInteger< N >::operator> ( const TBigInteger< N > &  rParam ) const [inline]

checks if the given integer is smaller

Parameters:
rParam: big number to check
Return values:
true: rParam is smaller
false,:rParam is bigger
template<int N>
void zeus::TBigInteger< N >::shiftLeft ( Int  iShift ) [inline]

shifts the big number to left

Parameters:
iShift: bits to shift
template<int N>
void zeus::TBigInteger< N >::shiftRight ( Int  iShift ) [inline]

shifts the big number to right

Parameters:
iShift: bits to shift
template<int N>
TBigInteger<N>& zeus::TBigInteger< N >::subtract ( const TBigInteger< N > &  rParam ) [inline]

subtracts a big value from this value

Parameters:
rParam: value to subtract
Returns:
this
template<int N>
void zeus::TBigInteger< N >::toByteArray ( IByteArray rData,
Int  iSize = N 
) const [inline]

Converts the big integer into a byte array

Parameters:
rData: [OUT] array
iSize: [IN] size to add

The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines


Written by Benjamin Hadorn http://www.xatlantis.ch.
Last change made on Sun Jan 22 2012 15:28:33