# Algorithms_in_C++: uint256_t Class Reference

Loading...
Searching...
No Matches
uint256_t Class Reference

class for 256-bit unsigned integer More...

`#include <uint256_t.hpp>`

Collaboration diagram for uint256_t:
[legend]

## Public Member Functions

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
| uint256_t (T low)
| Parameterized constructor. More...
| uint256_t (const std::string &str)
| Parameterized constructor. More...
| uint256_t (const uint256_t &num)=default
| Copy constructor. More...
| uint256_t (uint256_t &&num) noexcept
| Move constructor. More...
| uint256_t (uint128_t high, uint128_t low)
| Parameterized constructor. More...
| uint256_t (const uint64_t high, const uint64_t low)
| Parameterized constructor. More...
| ~uint256_t ()=default
| Destructor for uint256_t.
uint32_t | _lez ()
| Leading zeroes in binary. More...
uint32_t | _trz ()
| Trailing zeroes in binary. More...
| operator bool () const
| casting operator to boolean value More...
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
| operator T () const
| casting operator to any integer value More...
| operator uint128_t () const
| casting operator to uint128_t More...
uint128_t | lower () const
| returns lower 128-bit integer part More...
uint128_t | upper () const
| returns upper 128-bit integer part More...
uint256_t & | operator= (const uint256_t &p)=default
| operator = for uint256_t More...
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_t & | operator= (const T &p)
| operator = for other types More...
uint256_t & | operator= (const std::string &p)
| operator = for type string More...
uint256_t & | operator= (uint256_t &&p)=default
| Move assignment operator.
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_t | operator+ (const T &p)
| operator + for uint256_t and other integer types. More...
uint256_t | operator+ (const uint256_t &p)
| operator + for uint256_t and other integer types. More...
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_t & | operator+= (const T &p)
| operator += for uint256_t and other integer types. More...
uint256_t & | operator+= (const uint256_t &p)
| operator += for uint256_t More...
uint256_t & | operator++ ()
| pre-increment operator More...
uint256_t | operator++ (int)
| post-increment operator More...
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_t | operator- (const T &p)
| operator - for uint256_t and other integer types. More...
uint256_t | operator- (const uint256_t &p)
| operator - for uint256_t More...
uint256_t | operator- ()
| operator - using twos complement More...
uint256_t & | operator-- ()
| operator – (pre-decrement) More...
uint256_t | operator-- (int p)
| operator – (post-decrement) More...
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_t | operator-= (const T p)
| operator -= for uint256_t and other integer types. More...
uint256_t & | operator-= (const uint256_t &p)
| operator -= for uint256_t More...
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_t | operator* (const T &p)
| operator * for uint256_t and other integer types. More...
uint256_t | operator* (const uint256_t &p)
| operator * for uint256_t and other integer types. More...
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_t & | operator*= (const T &p)
| operator *= for uint256_t and other integer types. More...
uint256_t & | operator*= (const uint256_t &p)
| operator *= for uint256_t and other integer types. More...
std::pair< uint256_t, uint256_t > | divide (const uint256_t &p)
| divide function for uint256_t and other integer types. More...
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_t | operator/ (const T &p)
| operator / for uint256_t and other integer types. More...
uint256_t | operator/ (const uint256_t &p)
| operator / for uint256_t and other integer types. More...
uint256_t & | operator/= (const uint256_t &p)
| operator /= for uint256_t More...
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_t & | operator/= (const T &p)
| operator /= for uint256_t and other integer types. More...
uint256_t | operator% (const uint256_t &p)
| operator % for uint256_t More...
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_t | operator% (const T &p)
| operator % for uint256_t and other integer types. More...
uint256_t & | operator%= (const uint256_t &p)
| operator %= for uint256_t More...
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_t & | operator%= (const T &p)
| operator %= for uint256_t More...
bool | operator< (const uint256_t &other)
| operator < for uint256_t More...
bool | operator<= (const uint256_t &other)
| operator <= for uint256_t More...
bool | operator> (const uint256_t &other)
| operator > for uint256_t More...
bool | operator>= (const uint256_t &other)
| operator >= for uint256_t More...
bool | operator== (const uint256_t &other)
| operator == for uint256_t More...
bool | operator!= (const uint256_t &other)
| operator != for uint256_t More...
bool | operator! ()
| operator ! for uint256_t More...
bool | operator&& (const uint256_t &b)
| operator && for uint256_t More...
bool | operator|| (const uint256_t &b)
| operator || for uint256_t More...
bool | operator() ()
| operator () for uint256_t More...
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
bool | operator< (const T &other)
| operator < for other types More...
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
bool | operator<= (const T &other)
| operator <= for other types More...
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
bool | operator> (const T &other)
| operator > for other types More...
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
bool | operator>= (const T &other)
| operator >= for other types More...
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
bool | operator== (const T &other)
| operator == for other types More...
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
bool | operator!= (const T &other)
| operator != for other types More...
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
bool | operator&& (const T &b)
| operator && for other types More...
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
bool | operator|| (const T &b)
| operator || for other types More...
uint256_t | operator~ ()
| operator ~ for uint256_t More...
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_t | operator<< (const T &p)
| operator << for uint256_t More...
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_t & | operator<<= (const T &p)
| operator <<= for uint256_t More...
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_t | operator>> (const T &p)
| operator >> for uint256_t More...
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_t & | operator>>= (const T &p)
| operator >>= for uint256_t More...
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_t | operator& (const T &p)
| operator & for other types (bitwise operator) More...
uint256_t | operator& (const uint256_t &p)
| operator & for uint256_t (bitwise operator) More...
uint256_t & | operator&= (const uint256_t &p)
| operator &= for uint256_t (bitwise operator) More...
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_t & | operator&= (const T p)
| operator &= for other types (bitwise operator) More...
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_t | operator| (const T &p)
| operator | for other types (bitwise operator) More...
uint256_t | operator| (const uint256_t &p)
| operator | for uint256_t (bitwise operator) More...
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_t & | operator|= (const T &p)
| operator |= for other types (bitwise operator) More...
uint256_t & | operator|= (const uint256_t &p)
| operator |= for uint256_t (bitwise operator) More...
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_t | operator^ (const T &p)
| operator ^ for other types (bitwise operator) More...
uint256_t | operator^ (const uint256_t &p)
| operator ^ for uint256_t (bitwise operator) More...
uint256_t & | operator^= (const uint256_t &p)
| operator ^= for uint256_t (bitwise operator) More...
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_t & | operator^= (const T &p)
| operator ^= for other types (bitwise operator) More...

## Private Member Functions

void | __get_integer_from_string (const std::string &str)
| First and second half of 256 bit number. More...

## Private Attributes

uint128_t | f {}
uint128_t | s {}

## Friends

std::ostream & | operator<< (std::ostream &op, uint256_t p)
| operator << for printing uint256_t integer More...

## Detailed Description

class for 256-bit unsigned integer

## Constructor & Destructor Documentation

## uint256_t() [1/6]

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>

uint256_t::uint256_t | ( | T | low | ) |

inlineexplicit

Parameterized constructor.

Template Parameters

  T | template for integer types

Parameters

  low | Integer denoting lower 128-bits

: s(low), f(0) {}

## uint256_t() [2/6]

uint256_t::uint256_t | ( | const std::string & | str | ) |

inlineexplicit

Parameterized constructor.

Parameters

  str | Integer string (hexadecimal starting with 0x.. or decimal)

{
__get_integer_from_string(str);
}
uint256_t::__get_integer_from_string
void __get_integer_from_string(const std::string &str)
First and second half of 256 bit number.
Definition: uint256_t.hpp:43
Here is the call graph for this function:

## uint256_t() [3/6]

uint256_t::uint256_t | ( | const uint256_t & | num | ) |

default

Copy constructor.

Parameters

  num | 256-bit unsigned integer

## uint256_t() [4/6]

uint256_t::uint256_t | ( | uint256_t && | num | ) |

inlinenoexcept

Move constructor.

Parameters

  num | 256-bit unsigned integer

: f(std::move(num.f)), s(std::move(num.s)) {}
std::move
T move(T... args)

## uint256_t() [5/6]

uint256_t::uint256_t | ( | uint128_t | high,
|  | uint128_t | low
| ) |  |

inline

Parameterized constructor.

Parameters

  high | higher part 128-bit unsigned integer
  low | lower part 128-bit unsigned integer

: f(std::move(high)), s(std::move(low)) {}

## uint256_t() [6/6]

uint256_t::uint256_t | ( | const uint64_t | high,
|  | const uint64_t | low
| ) |  |

inline

Parameterized constructor.

Parameters

  high | higher part 64-bit unsigned integer
  low | lower part 64-bit unsigned integer

: f(high), s(low) {}

## Member Function Documentation

## __get_integer_from_string()

void uint256_t::__get_integer_from_string | ( | const std::string & | str | ) |

inlineprivate

First and second half of 256 bit number.

Get integer from given string.

Create an integer from a given string

Parameters

  str | integer string, can be hexadecimal (starting on 0x... or number)

Returns
  void

{
this->f = this->s = uint128_t(0);
if (str.size() > 1 && str[1] == 'x') {
for (auto i = 2; i < str.size(); ++i) {
*this *= 16LL;
if (str[i] >= '0' && str[i] <= '9') {
*this += (str[i] - '0');
} else if (str[i] >= 'A' && str[i] <= 'F') {
*this += (str[i] - 'A' + 10);
} else if (str[i] >= 'a' && str[i] <= 'f') {
*this += (str[i] - 'a' + 10);
}
}
} else {
for (auto &x : str) {
*this *= 10LL;
*this += (x - '0');
}
}
}
uint128_t
class for 128-bit unsigned integer
Definition: uint128_t.hpp:59
std::string::size
T size(T... args)
Here is the call graph for this function:

## _lez()

uint32_t uint256_t::_lez | ( |  | ) |

inline

Leading zeroes in binary.

Calculates leading zeros in 256-bit integer

Returns
  Integer denoting leading zeroes

{
if (f) {
return f._lez();
}
return 128 + s._lez();
}
uint128_t::_lez
uint32_t _lez()
Leading zeroes in binary.
Definition: uint128_t.hpp:139
Here is the call graph for this function:

## _trz()

uint32_t uint256_t::_trz | ( |  | ) |

inline

Trailing zeroes in binary.

Calculates leading zeros in 256-bit integer

Returns
  Integer denoting Trailing zeroes

{
if (s) {
return s._trz();
}
return 128 + f._trz();
}
uint128_t::_trz
uint32_t _trz()
Trailing zeroes in binary.
Definition: uint128_t.hpp:162
Here is the call graph for this function:

## divide()

std::pair< uint256_t, uint256_t > uint256_t::divide | ( | const uint256_t & | p | ) |

inline

divide function for uint256_t and other integer types.

divide this value and

Parameters

  p | 256-bit unsigned integer

Returns
  pair denoting quotient and remainder.

{
if (*this < p) { // if this is less than divisor
return {uint256_t(0), *this};
} else if (*this == p) { // if this is equal to divisor
return {uint256_t(1), uint256_t(0)};
}
uint256_t tmp = p, tmp2 = *this;
uint16_t left = tmp._lez() - _lez();
tmp <<= left;
uint256_t quotient(0);
uint256_t zero(0);
while (tmp2 >= p) {
uint16_t shf = tmp2._lez() - tmp._lez();
if (shf) {
tmp >>= shf;
quotient <<= shf;
left -= shf;
}
if (tmp2 < tmp) {
tmp >>= 1;
quotient <<= 1;
--left;
}
tmp2 -= tmp;
++quotient;
}
return {quotient << left, tmp2};
}
uint256_t
class for 256-bit unsigned integer
Definition: uint256_t.hpp:33
uint256_t::_lez
uint32_t _lez()
Leading zeroes in binary.
Definition: uint256_t.hpp:123
std::left
T left(T... args)
Here is the call graph for this function:

## lower()

uint128_t uint256_t::lower | ( |  | ) | const

inline

returns lower 128-bit integer part

Returns
  returns lower 128-bit integer part

{ return s; }

## operator bool()

uint256_t::operator bool | ( |  | ) | const

inlineexplicit

casting operator to boolean value

Returns
  true if value of this is non-zero, else false

{ return f || s; }

## operator T()

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>

uint256_t::operator T | ( |  | ) | const

inlineexplicit

casting operator to any integer value

Template Parameters

  T | any integer type

Returns
  integer value casted to mentioned type

{
return static_cast<T>(s);
}

## operator uint128_t()

uint256_t::operator uint128_t | ( |  | ) | const

inlineexplicit

casting operator to uint128_t

Returns
  returns lower 128-bit integer part

{ return s; }

## operator!()

bool uint256_t::operator! | ( |  | ) |

inline

operator ! for uint256_t

Returns
  true if this has zero value, else false

{ return !f && !s; }

## operator!=() [1/2]

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>

bool uint256_t::operator!= | ( | const T & | other | ) |

inline

operator != for other types

Template Parameters

  T | integral type

Parameters

  other | number to be compared with this

Returns
  true if this is not equal to other, else false

{
return *this != uint256_t(other);
}

## operator!=() [2/2]

bool uint256_t::operator!= | ( | const uint256_t & | other | ) |

inline

operator != for uint256_t

Parameters

  other | number to be compared with this

Returns
  true if this is not equal than other, else false

{
return !((*this) == other);
}

## operator%() [1/2]

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>

uint256_t uint256_t::operator% | ( | const T & | p | ) |

inline

operator % for uint256_t and other integer types.

Template Parameters

  T | denoting integral type

Parameters

  p | a type of integer variable

Returns
  unsigned 256-bit remainder.

{
uint256_t tmp = *this;
tmp %= uint256_t(p);
return tmp;
}

## operator%() [2/2]

uint256_t uint256_t::operator% | ( | const uint256_t & | p | ) |

inline

operator % for uint256_t

Parameters

  p | 256-bit unsigned integer

Returns
  unsigned 256-bit remainder.

{ return divide(p).second; }
uint256_t::divide
std::pair< uint256_t, uint256_t > divide(const uint256_t &p)
divide function for uint256_t and other integer types.
Definition: uint256_t.hpp:421
Here is the call graph for this function:

## operator%=() [1/2]

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>

uint256_t & uint256_t::operator%= | ( | const T & | p | ) |

inline

operator %= for uint256_t

Template Parameters

  T | denoting integral type

Parameters

  p | a type of integer variable

Returns
  this set as unsigned 256-bit remainder.

{
*this %= uint256_t(p);
return *this;
}

## operator%=() [2/2]

uint256_t & uint256_t::operator%= | ( | const uint256_t & | p | ) |

inline

operator %= for uint256_t

Parameters

  p | 256-bit unsigned integer

Returns
  this set as unsigned 256-bit remainder.

{
*this = divide(p).second;
return *this;
}
Here is the call graph for this function:

## operator&() [1/2]

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>

uint256_t uint256_t::operator& | ( | const T & | p | ) |

inline

operator & for other types (bitwise operator)

Template Parameters

  T | integral type

Parameters

  p | number to be operated

Returns
  value of this & p (& is bit-wise operator)

{
return *this & uint256_t(p);
}

## operator&() [2/2]

uint256_t uint256_t::operator& | ( | const uint256_t & | p | ) |

inline

operator & for uint256_t (bitwise operator)

Parameters

  p | number to be operated

Returns
  value of this & p (& is bit-wise operator)

{
return {f & p.f, s & p.s};
}

## operator&&() [1/2]

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>

bool uint256_t::operator&& | ( | const T & | b | ) |

inline

operator && for other types

Template Parameters

  T | integral type

Parameters

  other | number to be compared with this

Returns
  true if this is both values are non-zero, else false

{
return (s || f) && (b);
}

## operator&&() [2/2]

bool uint256_t::operator&& | ( | const uint256_t & | b | ) |

inline

operator && for uint256_t

Parameters

  b | number to be compared with this

Returns
  true if both of the values are not zero, else false

{
return (s || f) && (b.s || b.f);
}

## operator&=() [1/2]

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>

uint256_t & uint256_t::operator&= | ( | const T | p | ) |

inline

operator &= for other types (bitwise operator)

Template Parameters

  T | integral type

Parameters

  p | number to be operated

Returns
  this = this & p (& is bit-wise operator)

{
s &= p.s;
return *this;
}

## operator&=() [2/2]

uint256_t & uint256_t::operator&= | ( | const uint256_t & | p | ) |

inline

operator &= for uint256_t (bitwise operator)

Parameters

  p | number to be operated

Returns
  this = this & p (& is bit-wise operator)

{
f &= p.f;
s &= p.s;
return *this;
}

## operator()()

bool uint256_t::operator() | ( |  | ) |

inline

operator () for uint256_t

Returns
  true if this value is non-zero, else false

{ return s || f; }

## operator*() [1/2]

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>

uint256_t uint256_t::operator* | ( | const T & | p | ) |

inline

operator * for uint256_t and other integer types.

Template Parameters

  T | denoting integral type

Parameters

  p | a type of integer variable

Returns
  multiplication of this and p, returning uint256_t integer

{
return *this * uint256_t(p);
}

## operator*() [2/2]

uint256_t uint256_t::operator* | ( | const uint256_t & | p | ) |

inline

operator * for uint256_t and other integer types.

Parameters

  p | 256-bit unsigned integer

Returns
  multiplication of this and p, returning uint256_t integer

{
uint128_t f_first(s.upper()), f_second(s.lower()), s_first(p.s.upper()),
s_second(p.s.lower());
uint128_t fi = f_first * s_first, se = f_first * s_second,
th = s_first * f_second, fo = s_second * f_second;
uint128_t tmp = se << 64, tmp2 = th << 64;
int cc = (tmp + tmp2 < tmp);
tmp += tmp2;
cc += (tmp + fo < tmp);
return {f * p.s + s * p.f + fi + se.upper() + th.upper() + cc,
tmp + fo};
}
uint128_t::upper
uint64_t upper() const
returns upper 64-bit integer part
Definition: uint128_t.hpp:207
uint128_t::lower
uint64_t lower() const
returns lower 64-bit integer part
Definition: uint128_t.hpp:201
Here is the call graph for this function:

## operator*=() [1/2]

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>

uint256_t & uint256_t::operator*= | ( | const T & | p | ) |

inline

operator *= for uint256_t and other integer types.

Template Parameters

  T | denoting integral type

Parameters

  p | a type of integer variable

Returns
  multiplication of this and p, returning this

{
return (*this *= uint256_t(p));
}

## operator*=() [2/2]

uint256_t & uint256_t::operator*= | ( | const uint256_t & | p | ) |

inline

operator *= for uint256_t and other integer types.

Parameters

  p | 256-bit unsigned integer

Returns
  multiplication of this and p, returning this

{
uint128_t f_first(s.upper()), f_second(s.lower()), s_first(p.s.upper()),
s_second(p.s.lower());
uint128_t fi = f_first * s_first, se = f_first * s_second,
th = s_first * f_second, fo = s_second * f_second;
uint128_t tmp = se << 64, tmp2 = th << 64;
int cc = (tmp + tmp2 < tmp);
tmp += tmp2;
cc += (tmp + fo < tmp);
f = f * p.s + s * p.f + fi + se.upper() + th.upper() + cc;
s = tmp + fo;
return *this;
}
Here is the call graph for this function:

## operator+() [1/2]

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>

uint256_t uint256_t::operator+ | ( | const T & | p | ) |

inline

operator + for uint256_t and other integer types.

Template Parameters

  T | denoting integral type

Parameters

  p | a type of integer variable

Returns
  addition of this and p, returning uint256_t integer

{
bool app = s + p < s;
return uint256_t(f + app, s + p);
}

## operator+() [2/2]

uint256_t uint256_t::operator+ | ( | const uint256_t & | p | ) |

inline

operator + for uint256_t and other integer types.

Parameters

  p | 256-bit unsigned integer

Returns
  addition of this and p, returning uint256_t integer

{
bool app = (s + p.s < s);
return {f + app + p.f, s + p.s};
}

## operator++() [1/2]

uint256_t & uint256_t::operator++ | ( |  | ) |

inline

pre-increment operator

Returns
  incremented value of this.

{
*this += 1;
return *this;
}

## operator++() [2/2]

uint256_t uint256_t::operator++ | ( | int |  | ) |

inline

post-increment operator

Returns
  incremented value of this.

{
++*this;
return *this;
}

## operator+=() [1/2]

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>

uint256_t & uint256_t::operator+= | ( | const T & | p | ) |

inline

operator += for uint256_t and other integer types.

Template Parameters

  T | denoting integral type

Parameters

  p | a type of integer variable

Returns
  addition of this and p, returning this

{
bool app = (p + s < s);
this->f += app;
this->s += p;
return *this;
}

## operator+=() [2/2]

uint256_t & uint256_t::operator+= | ( | const uint256_t & | p | ) |

inline

operator += for uint256_t

Parameters

  p | 256-bit unsigned integer

Returns
  addition of this and p, returning this

{
bool app = (s + p.s < s);
f = f + app + p.f;
s = s + p.s;
return *this;
}

## operator-() [1/3]

uint256_t uint256_t::operator- | ( |  | ) |

inline

operator - using twos complement

Returns
  2's complement of this.

{ return ~*this + uint256_t(1); }

## operator-() [2/3]

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>

uint256_t uint256_t::operator- | ( | const T & | p | ) |

inline

operator - for uint256_t and other integer types.

Template Parameters

  T | denoting integral type

Parameters

  p | a type of integer variable

Returns
  subtraction of this and p, returning uint256_t integer

{
bool app = (p > s);
return uint256_t(f - app, s - p);
}

## operator-() [3/3]

uint256_t uint256_t::operator- | ( | const uint256_t & | p | ) |

inline

operator - for uint256_t

Parameters

  p | a type of integer variable

Returns
  subtraction of this and p, returning uint256_t integer

{
bool app = s < p.s;
return {f - p.f - app, s - p.s};
}

## operator--() [1/2]

uint256_t & uint256_t::operator-- | ( |  | ) |

inline

operator – (pre-decrement)

Returns
  decremented value of this

{
*this -= 1;
return *this;
}

## operator--() [2/2]

uint256_t uint256_t::operator-- | ( | int | p | ) |

inline

operator – (post-decrement)

Returns
  decremented value of this

{
--*this;
return *this;
}

## operator-=() [1/2]

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>

uint256_t uint256_t::operator-= | ( | const T | p | ) |

inline

operator -= for uint256_t and other integer types.

Template Parameters

  T | denoting integral type

Parameters

  p | a type of integer variable

Returns
  subtraction of this and p, returning this

{
bool app = (p > s);
f = f - app;
s = s - p;
return *this;
}

## operator-=() [2/2]

uint256_t & uint256_t::operator-= | ( | const uint256_t & | p | ) |

inline

operator -= for uint256_t

Parameters

  p | 256-bit unsigned integer

Returns
  subtraction of this and p, returning this

{
bool app = s < p.s;
f = f - app - p.f;
s = s - p.s;
return *this;
}

## operator/() [1/2]

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>

uint256_t uint256_t::operator/ | ( | const T & | p | ) |

inline

operator / for uint256_t and other integer types.

Template Parameters

  T | denoting integral type

Parameters

  p | a type of integer variable

Returns
  unsigned 256-bit quotient.

{
uint256_t tmp = *this;
tmp /= uint256_t(p);
return tmp;
}

## operator/() [2/2]

uint256_t uint256_t::operator/ | ( | const uint256_t & | p | ) |

inline

operator / for uint256_t and other integer types.

Parameters

  p | 256-bit unsigned integer

Returns
  unsigned 256-bit quotient.

{ return divide(p).first; }
Here is the call graph for this function:

## operator/=() [1/2]

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>

uint256_t & uint256_t::operator/= | ( | const T & | p | ) |

inline

operator /= for uint256_t and other integer types.

Template Parameters

  T | denoting integral type

Parameters

  p | a type of integer variable

Returns
  this set as unsigned 256-bit quotient.

{
*this /= uint256_t(p);
return *this;
}

## operator/=() [2/2]

uint256_t & uint256_t::operator/= | ( | const uint256_t & | p | ) |

inline

operator /= for uint256_t

Parameters

  p | 256-bit unsigned integer

Returns
  this set as unsigned 256-bit quotient.

{
*this = divide(p).first;
return *this;
}
Here is the call graph for this function:

## operator<() [1/2]

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>

bool uint256_t::operator< | ( | const T & | other | ) |

inline

operator < for other types

Template Parameters

  T | integral type

Parameters

  other | number to be compared with this

Returns
  true if this is less than other, else false

{
return *this < uint256_t(other);
}

## operator<() [2/2]

bool uint256_t::operator< | ( | const uint256_t & | other | ) |

inline

operator < for uint256_t

Parameters

  other | number to be compared with this

Returns
  true if this is less than other, else false

{
return f < other.f || (f == other.f && s < other.s);
}

## operator<<()

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>

uint256_t uint256_t::operator<< | ( | const T & | p | ) |

inline

operator << for uint256_t

Template Parameters

  T | integral type

Parameters

  p | number denoting number of shifts

Returns
  value of this shifted by p to left

{
if (!p) {
return {this->f, this->s};
} else if (p >= 128) {
return uint256_t((this->s << (p - 128)), uint128_t(0));
}
return uint256_t((this->f << p) + (this->s >> (128 - p)),
(this->s << p));
}

## operator<<=()

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>

uint256_t & uint256_t::operator<<= | ( | const T & | p | ) |

inline

operator <<= for uint256_t

Template Parameters

  T | integral type

Parameters

  p | number denoting number of shifts

Returns
  this shifted by p to left

{
if (p) {
if (p >= 128) {
this->f = (this->s << (p - 128));
this->s = uint128_t(0);
} else {
f = ((this->s >> (128 - p)) + (this->f << p));
s = (this->s << p);
}
}
return *this;
}

## operator<=() [1/2]

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>

bool uint256_t::operator<= | ( | const T & | other | ) |

inline

operator <= for other types

Template Parameters

  T | integral type

Parameters

  other | number to be compared with this

Returns
  true if this is less than or equal to other, else false

{
return *this <= uint256_t(other);
}

## operator<=() [2/2]

bool uint256_t::operator<= | ( | const uint256_t & | other | ) |

inline

operator <= for uint256_t

Parameters

  other | number to be compared with this

Returns
  true if this is less than or equal to other, else false

{
return f < other.f || (f == other.f && s <= other.s);
}

## operator=() [1/3]

uint256_t & uint256_t::operator= | ( | const std::string & | p | ) |

inline

operator = for type string

Parameters

  p | a string to assign it's value to equivalent integer

Returns
  this pointer with it's value equal to `p`

{
__get_integer_from_string(p);
return *this;
}
Here is the call graph for this function:

## operator=() [2/3]

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>

uint256_t & uint256_t::operator= | ( | const T & | p | ) |

inline

operator = for other types

Template Parameters

  T | denoting any integer type

Parameters

  p | an integer to assign it's value

Returns
  this pointer with it's value equal to `p`

{
this->s = p;
return *this;
}

## operator=() [3/3]

uint256_t & uint256_t::operator= | ( | const uint256_t & | p | ) |

inlinedefault

operator = for uint256_t

Parameters

  p | an 256-bit integer to assign it's value

Returns
  this pointer with it's value equal to `p`

## operator==() [1/2]

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>

bool uint256_t::operator== | ( | const T & | other | ) |

inline

operator == for other types

Template Parameters

  T | integral type

Parameters

  other | number to be compared with this

Returns
  true if this is equal to other, else false

{
return *this == uint256_t(other);
}

## operator==() [2/2]

bool uint256_t::operator== | ( | const uint256_t & | other | ) |

inline

operator == for uint256_t

Parameters

  other | number to be compared with this

Returns
  true if this is equal than other, else false

{
return f == other.f && s == other.s;
}

## operator>() [1/2]

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>

bool uint256_t::operator> | ( | const T & | other | ) |

inline

operator > for other types

Template Parameters

  T | integral type

Parameters

  other | number to be compared with this

Returns
  true if this is greater than other, else false

{
return *this > uint256_t(other);
}

## operator>() [2/2]

bool uint256_t::operator> | ( | const uint256_t & | other | ) |

inline

operator > for uint256_t

Parameters

  other | number to be compared with this

Returns
  true if this is greater than other, else false

{
return f > other.f || (f == other.f && s > other.s);
}

## operator>=() [1/2]

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>

bool uint256_t::operator>= | ( | const T & | other | ) |

inline

operator >= for other types

Template Parameters

  T | integral type

Parameters

  other | number to be compared with this

Returns
  true if this is greater than or equal other, else false

{
return *this >= uint256_t(other);
}

## operator>=() [2/2]

bool uint256_t::operator>= | ( | const uint256_t & | other | ) |

inline

operator >= for uint256_t

Parameters

  other | number to be compared with this

Returns
  true if this is greater than or equal than other, else false

{
return (f > other.f) || (f == other.f && s >= other.s);
}

## operator>>()

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>

uint256_t uint256_t::operator>> | ( | const T & | p | ) |

inline

operator >> for uint256_t

Template Parameters

  T | integral type

Parameters

  p | number denoting number of shifts

Returns
  value of this shifted by p to right

{
if (!p) {
return {this->f, this->s};
} else if (p >= 128) {
return uint256_t(uint128_t(0), (this->f >> (p - 128)));
}
return uint256_t((this->f >> p),
(this->s >> p) + (this->f << (128 - p)));
}

## operator>>=()

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>

uint256_t & uint256_t::operator>>= | ( | const T & | p | ) |

inline

operator >>= for uint256_t

Template Parameters

  T | integral type

Parameters

  p | number denoting number of shifts

Returns
  this shifted by p to right

{
if (p) {
if (p >= 128) {
f = uint128_t(0);
s = (this->f >> (p - 128));
} else {
s = (this->s >> p) + (this->f << (128 - p));
f = (this->f >> p);
}
}
return *this;
}

## operator^() [1/2]

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>

uint256_t uint256_t::operator^ | ( | const T & | p | ) |

inline

operator ^ for other types (bitwise operator)

Template Parameters

  T | integral type

Parameters

  p | number to be operated

Returns
  value of this ^ p (^ is bit-wise XOR operator)

{
return uint256_t(f, s ^ p);
}

## operator^() [2/2]

uint256_t uint256_t::operator^ | ( | const uint256_t & | p | ) |

inline

operator ^ for uint256_t (bitwise operator)

Parameters

  p | number to be operated

Returns
  value of this ^ p (^ is bit-wise XOR operator)

{
return {this->f ^ p.f, this->s ^ p.s};
}

## operator^=() [1/2]

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>

uint256_t & uint256_t::operator^= | ( | const T & | p | ) |

inline

operator ^= for other types (bitwise operator)

Template Parameters

  T | integral type

Parameters

  p | number to be operated

Returns
  this = this ^ p (^ is bit-wise XOR operator)

{
s ^= p;
return *this;
}

## operator^=() [2/2]

uint256_t & uint256_t::operator^= | ( | const uint256_t & | p | ) |

inline

operator ^= for uint256_t (bitwise operator)

Parameters

  p | number to be operated

Returns
  this = this ^ p (^ is bit-wise XOR operator)

{
f ^= p.f;
s ^= p.s;
return *this;
}

## operator|() [1/2]

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>

uint256_t uint256_t::operator| | ( | const T & | p | ) |

inline

operator | for other types (bitwise operator)

Template Parameters

  T | integral type

Parameters

  p | number to be operated

Returns
  value of this | p (| is bit-wise operator)

{
return *this | uint256_t(p);
}

## operator|() [2/2]

uint256_t uint256_t::operator| | ( | const uint256_t & | p | ) |

inline

operator | for uint256_t (bitwise operator)

Parameters

  p | number to be operated

Returns
  value of this | p (| is bit-wise OR operator)

{
return {this->f | p.f, this->s | p.s};
}

## operator|=() [1/2]

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>

uint256_t & uint256_t::operator|= | ( | const T & | p | ) |

inline

operator |= for other types (bitwise operator)

Template Parameters

  T | integral type

Parameters

  p | number to be operated

Returns
  this = this | p (| is bit-wise OR operator)

{
s |= p;
return *this;
}

## operator|=() [2/2]

uint256_t & uint256_t::operator|= | ( | const uint256_t & | p | ) |

inline

operator |= for uint256_t (bitwise operator)

Parameters

  p | number to be operated

Returns
  this = this | p (| is bit-wise OR operator)

{
f |= p.f;
s |= p.s;
return *this;
}

## operator||() [1/2]

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>

bool uint256_t::operator|| | ( | const T & | b | ) |

inline

operator || for other types

Template Parameters

  T | integral type

Parameters

  other | number to be compared with this

Returns
  true if this is either one of the values are non-zero, else false

{
return (s || f) || (b);
}

## operator||() [2/2]

bool uint256_t::operator|| | ( | const uint256_t & | b | ) |

inline

operator || for uint256_t

Parameters

  b | number to be compared with this

Returns
  true if one of the values are not zero, else false

{
return (s || f) || (b.s || b.f);
}

## operator~()

uint256_t uint256_t::operator~ | ( |  | ) |

inline

operator ~ for uint256_t

Returns
  1's complement of this number

{ return {~f, ~s}; }

## upper()

uint128_t uint256_t::upper | ( |  | ) | const

inline

returns upper 128-bit integer part

Returns
  returns upper 128-bit integer part

{ return f; }

## Friends And Related Function Documentation

## operator<<

std::ostream & operator<< | ( | std::ostream & | op,
|  | uint256_t | p
| ) |  |

friend

operator << for printing uint256_t integer

Prints the uint256_t integer in decimal form

Note
  Note that this operator is costly since it uses strings to print the value

Parameters

  op | ostream object
  p | 256-bit integer

Returns
  op, ostream object.

{
if (!p.f) {
op << p.s;
} else {
std::string out = "0", p_2 = "1";
uint128_t L(1);
for (uint64_t i = 0; i < 128; ++i) {
if ((p.s & L)) {
out = add(out, p_2);
}
p_2 = add(p_2, p_2);
L <<= 1;
}
L = uint128_t(1);
for (int i = 0; i < 128; ++i) {
if ((p.f & L)) {
out = add(out, p_2);
}
p_2 = add(p_2, p_2);
L <<= 1;
}
op << out;
}
return op;
}
std::string
add
std::string add(const std::string &first, const std::string &second)
Adding two string.
Definition: uint128_t.hpp:37

The documentation for this class was generated from the following file:

- ciphers/uint256_t.hpp