diff --git a/uint128_t.cpp b/uint128_t.cpp index bae8026..5a0b0b1 100644 --- a/uint128_t.cpp +++ b/uint128_t.cpp @@ -11,6 +11,10 @@ uint128_t::uint128_t(const char *s) { init(s); } +uint128_t::uint128_t(const bool & b) + : uint128_t((uint8_t) b) +{} + void uint128_t::init(const char *s) { if (s == NULL || s[0] == 0) { uint128_t(); return; } if (s[1] == 'x') @@ -49,6 +53,12 @@ uint8_t uint128_t::HexToInt(const char *s) const { return ret; } +uint128_t & uint128_t::operator=(const bool & rhs) { + UPPER = 0; + LOWER = rhs; + return *this; +} + uint128_t::operator bool() const{ return (bool) (UPPER | LOWER); } diff --git a/uint128_t.include b/uint128_t.include index b583fe2..21fdaa6 100644 --- a/uint128_t.include +++ b/uint128_t.include @@ -69,6 +69,7 @@ class uint128_t{ uint128_t(uint128_t && rhs) = default; uint128_t(std::string & s); uint128_t(const char *s); + uint128_t(const bool & b); template ::value, T>::type > uint128_t(const T & rhs) @@ -116,6 +117,8 @@ class uint128_t{ return *this; } + uint128_t & operator=(const bool & rhs); + // Typecast Operators operator bool() const; operator uint8_t() const; diff --git a/uint256_t.cpp b/uint256_t.cpp index 9db2194..e4f287d 100644 --- a/uint256_t.cpp +++ b/uint256_t.cpp @@ -25,6 +25,10 @@ uint256_t::uint256_t(const char * s, uint8_t base) { init_from_base(s, base); } +uint256_t::uint256_t(const bool & b) + : uint256_t((uint8_t) b) +{} + void uint256_t::init(const char * s) { //create from string char buffer[64]; @@ -66,6 +70,12 @@ void uint256_t::init_from_base(const char * s, uint8_t base) { } } +uint256_t & uint256_t::operator=(const bool & rhs) { + UPPER = 0; + LOWER = rhs; + return *this; +} + uint256_t::operator bool() const{ return (bool) (UPPER | LOWER); } diff --git a/uint256_t.include b/uint256_t.include index d9ec879..3cc2a6f 100644 --- a/uint256_t.include +++ b/uint256_t.include @@ -64,6 +64,7 @@ class uint256_t{ uint256_t(const char *val); uint256_t(const std::string & s, uint8_t base); uint256_t(const char *val, uint8_t base); + uint256_t(const bool & b); template ::value, T>::type > uint256_t(const T & rhs) @@ -144,6 +145,8 @@ class uint256_t{ return *this; } + uint256_t & operator=(const bool & rhs); + // Typecast Operators operator bool () const; operator uint8_t () const;