-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
as-iotex
committed
Apr 11, 2022
1 parent
a92c0bc
commit b90156e
Showing
6 changed files
with
145 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include "bignum/bignum.h" | ||
|
||
using namespace iotex::bignum; | ||
|
||
Bignum::Bignum() | ||
{ | ||
_u256 = uint256_0; | ||
} | ||
|
||
Bignum::Bignum(const char* str, NumericBase base) | ||
{ | ||
uint8_t baseInt = 16; | ||
if (base == NumericBase::Base10) { baseInt = 10; } | ||
|
||
_u256 = uint256_t(str, baseInt); | ||
} | ||
|
||
IotexString Bignum::ToString(NumericBase base) const | ||
{ | ||
if (base == NumericBase::Base10) | ||
{ | ||
return _u256.str(10); | ||
} | ||
else if (base == NumericBase::Base16) | ||
{ | ||
return _u256.str(16); | ||
} | ||
else return ""; | ||
} | ||
|
||
Bignum& Bignum::operator=(const Bignum& bignum) | ||
{ | ||
_u256 = uint256_t(bignum.ToString(NumericBase::Base16), 16); | ||
return *this; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#pragma once | ||
|
||
#include "extern/uint256_t/uint256_t.h" | ||
#include "helpers/client_helper.h" | ||
|
||
namespace iotex | ||
{ | ||
namespace bignum | ||
{ | ||
enum NumericBase | ||
{ | ||
Base10, | ||
Base16 | ||
}; | ||
|
||
/** | ||
* @brief Represents an unigned integer of up to 256 bytes. | ||
* | ||
*/ | ||
class Bignum | ||
{ | ||
public: | ||
/** | ||
* @brief Default constructor. Constructs a Bignum with the value of 0. | ||
*/ | ||
Bignum(); | ||
|
||
/** | ||
* @brief Constructs a Bignum from a string value. | ||
* | ||
* @param str The value. | ||
* @param base The numeric base of the string (Decimal or Hexadecimal). | ||
*/ | ||
Bignum(const char* str, NumericBase base); | ||
|
||
/** | ||
* @brief Returns the value as a string. | ||
* | ||
* @param base The numeric base to use (Decimal or Hexadecimal). | ||
*/ | ||
IotexString ToString(NumericBase base) const; | ||
|
||
Bignum& operator=(const Bignum& bignum); | ||
|
||
private: | ||
uint256_t _u256; | ||
}; | ||
} // namespace bignum | ||
} // namespace iotex |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters