veriblock-pop-cpp
C++11 Libraries for leveraging VeriBlock Proof-Of-Proof blockchain technology.
altintegration::ArithUint256 Class Reference

256-bit unsigned big integer. More...

Detailed Description

Definition at line 35 of file arith_uint256.hpp.

#include <arith_uint256.hpp>

+ Inheritance diagram for altintegration::ArithUint256:
+ Collaboration diagram for altintegration::ArithUint256:

Public Member Functions

 ArithUint256 (const std::vector< uint8_t > &v)
 
template<size_t N>
 ArithUint256 (const Blob< N > &b)
 
 ArithUint256 (uint64_t b)
 
const ArithUint256 operator~ () const
 
const ArithUint256 operator- () const
 
ArithUint256operator= (uint64_t b)
 
ArithUint256operator^= (const ArithUint256 &b)
 
ArithUint256operator&= (const ArithUint256 &b)
 
ArithUint256operator|= (const ArithUint256 &b)
 
ArithUint256operator^= (uint64_t b)
 
ArithUint256operator|= (uint64_t b)
 
ArithUint256operator<<= (unsigned int shift)
 
ArithUint256operator>>= (unsigned int shift)
 
ArithUint256operator+= (const ArithUint256 &b)
 
ArithUint256operator-= (const ArithUint256 &b)
 
ArithUint256operator+= (uint64_t b64)
 
ArithUint256operator-= (uint64_t b64)
 
ArithUint256operator*= (uint32_t b32)
 
ArithUint256operator*= (const ArithUint256 &b)
 
ArithUint256operator/= (const ArithUint256 &b)
 
ArithUint256operator++ ()
 
const ArithUint256 operator++ (int)
 
ArithUint256operator-- ()
 
const ArithUint256 operator-- (int)
 
unsigned int bits () const
 Returns the position of the highest bit set plus one, or zero if the value is zero.
 
int compareTo (const ArithUint256 &b) const
 
std::string toString () const
 
std::string toHex () const
 
uint64_t getLow64 () const
 
uint32_t toBits (bool negative=false) const
 
void setHex (const std::string &value)
 
- Public Member Functions inherited from altintegration::Blob< SHA256_HASH_SIZE >
 Blob (const std::initializer_list< uint8_t > &list)
 
 Blob (Slice< const uint8_t > slice)
 
 Blob (const std::vector< uint8_t > &v)
 
 Blob (const std::string &hex)
 
Blob< N > & operator= (const Slice< const uint8_t > slice)
 
Blob< N > & operator= (const std::vector< uint8_t > &vec)
 
Blob< N > reverse () const
 
Blob< N > & operator~ ()
 
std::vector< value_type > asVector () const
 
std::string asString () const
 
const value_type & operator[] (size_t index) noexcept
 
const value_type & operator[] (size_t index) const noexcept
 
int compareTo (const Blob< N > &b) const
 

Static Public Member Functions

static ArithUint256 fromString (const std::string &num)
 
static ArithUint256 fromHex (const std::string &hex)
 
template<size_t N>
static ArithUint256 fromLEBytes (const Blob< N > &b)
 
static ArithUint256 fromBits (uint32_t bits, bool *negative=nullptr, bool *overflow=nullptr)
 

Friends

const ArithUint256 operator+ (const ArithUint256 &a, const ArithUint256 &b)
 
const ArithUint256 operator- (const ArithUint256 &a, const ArithUint256 &b)
 
const ArithUint256 operator* (const ArithUint256 &a, const ArithUint256 &b)
 
const ArithUint256 operator/ (const ArithUint256 &a, const ArithUint256 &b)
 
const ArithUint256 operator| (const ArithUint256 &a, const ArithUint256 &b)
 
const ArithUint256 operator& (const ArithUint256 &a, const ArithUint256 &b)
 
const ArithUint256 operator^ (const ArithUint256 &a, const ArithUint256 &b)
 
const ArithUint256 operator>> (const ArithUint256 &a, int shift)
 
const ArithUint256 operator<< (const ArithUint256 &a, int shift)
 
const ArithUint256 operator* (const ArithUint256 &a, uint32_t b)
 
bool operator> (const ArithUint256 &a, const ArithUint256 &b)
 
bool operator< (const ArithUint256 &a, const ArithUint256 &b)
 
bool operator>= (const ArithUint256 &a, const ArithUint256 &b)
 
bool operator<= (const ArithUint256 &a, const ArithUint256 &b)
 
bool operator== (const ArithUint256 &a, uint64_t b)
 

Additional Inherited Members

- Public Types inherited from altintegration::Blob< SHA256_HASH_SIZE >
using value_type = uint8_t
 
using storage_t = std::array< value_type, N >
 
using pointer = typename storage_t::pointer
 
using const_pointer = typename storage_t::const_pointer
 
using reference = typename storage_t::reference
 
using const_reference = typename storage_t::const_reference
 
using iterator = typename storage_t::iterator
 
using const_iterator = typename storage_t::const_iterator
 
using size_type = typename storage_t::size_type
 
using difference_type = typename storage_t::difference_type
 
using reverse_iterator = typename storage_t::reverse_iterator
 
using const_reverse_iterator = typename storage_t::const_reverse_iterator
 
- Public Attributes inherited from altintegration::Blob< SHA256_HASH_SIZE >
 data_
 
return * this
 

Constructor & Destructor Documentation

◆ ArithUint256() [1/3]

altintegration::ArithUint256::ArithUint256 ( const std::vector< uint8_t > &  v)
inline

Definition at line 39 of file arith_uint256.hpp.

39: Blob<SHA256_HASH_SIZE>(v) {}

◆ ArithUint256() [2/3]

template<size_t N>
altintegration::ArithUint256::ArithUint256 ( const Blob< N > &  b)
inline

Definition at line 43 of file arith_uint256.hpp.

43 {
44 VBK_ASSERT(b.size() <= SHA256_HASH_SIZE);
45 assign(b);
46 }
constexpr const auto SHA256_HASH_SIZE
sha256 hash size
Definition: consts.hpp:39

◆ ArithUint256() [3/3]

altintegration::ArithUint256::ArithUint256 ( uint64_t  b)
inline

Definition at line 48 of file arith_uint256.hpp.

48 {
49 data_[0] = (uint8_t)b;
50 data_[1] = (uint8_t)(b >> 8);
51 data_[2] = (uint8_t)(b >> 16);
52 data_[3] = (uint8_t)(b >> 24);
53 data_[4] = (uint8_t)(b >> 32);
54 data_[5] = (uint8_t)(b >> 40);
55 data_[6] = (uint8_t)(b >> 48);
56 data_[7] = (uint8_t)(b >> 56);
57 for (int i = 8; i < SHA256_HASH_SIZE; i++) {
58 data_[i] = 0;
59 }
60 }

Member Function Documentation

◆ fromHex()

static ArithUint256 altintegration::ArithUint256::fromHex ( const std::string &  hex)
static
Exceptions
uint_error

◆ fromLEBytes()

template<size_t N>
static ArithUint256 altintegration::ArithUint256::fromLEBytes ( const Blob< N > &  b)
inlinestatic

Definition at line 277 of file arith_uint256.hpp.

277 {
278 return ArithUint256(b.reverse());
279 }

◆ operator&=()

ArithUint256 & altintegration::ArithUint256::operator&= ( const ArithUint256 b)
inline

Definition at line 101 of file arith_uint256.hpp.

101 {
102 for (int i = 0; i < SHA256_HASH_SIZE; i++) {
103 data_[i] &= b.data_[i];
104 }
105 return *this;
106 }

◆ operator++() [1/2]

ArithUint256 & altintegration::ArithUint256::operator++ ( )
inline

Definition at line 175 of file arith_uint256.hpp.

175 {
176 // prefix operator
177 for (int i = 0; i < SHA256_HASH_SIZE && ++data_[i] == 0; ++i) {
178 }
179 return *this;
180 }

◆ operator++() [2/2]

const ArithUint256 altintegration::ArithUint256::operator++ ( int  )
inline

Definition at line 182 of file arith_uint256.hpp.

182 {
183 // postfix operator
184 const ArithUint256 ret = *this;
185 ++(*this);
186 return ret;
187 }

◆ operator+=() [1/2]

ArithUint256 & altintegration::ArithUint256::operator+= ( const ArithUint256 b)
inline

Definition at line 142 of file arith_uint256.hpp.

142 {
143 uint64_t carry = 0;
144 for (int i = 0; i < SHA256_HASH_SIZE; i++) {
145 uint64_t n = carry + data_[i] + b.data_[i];
146 data_[i] = n & 0xff;
147 carry = n >> 8;
148 }
149 return *this;
150 }

◆ operator+=() [2/2]

ArithUint256 & altintegration::ArithUint256::operator+= ( uint64_t  b64)
inline

Definition at line 157 of file arith_uint256.hpp.

157 {
158 ArithUint256 b;
159 b = b64;
160 *this += b;
161 return *this;
162 }

◆ operator-()

const ArithUint256 altintegration::ArithUint256::operator- ( ) const
inline

Definition at line 70 of file arith_uint256.hpp.

70 {
71 ArithUint256 ret;
72 for (int i = 0; i < SHA256_HASH_SIZE; i++) {
73 ret.data_[i] = ~data_[i];
74 }
75 ++ret;
76 return ret;
77 }

◆ operator--() [1/2]

ArithUint256 & altintegration::ArithUint256::operator-- ( )
inline

Definition at line 189 of file arith_uint256.hpp.

189 {
190 // prefix operator
191 for (int i = 0; i < SHA256_HASH_SIZE &&
192 --data_[i] == (std::numeric_limits<uint8_t>::max)();
193 ++i) {
194 }
195 return *this;
196 }

◆ operator--() [2/2]

const ArithUint256 altintegration::ArithUint256::operator-- ( int  )
inline

Definition at line 198 of file arith_uint256.hpp.

198 {
199 // postfix operator
200 const ArithUint256 ret = *this;
201 --(*this);
202 return ret;
203 }

◆ operator-=() [1/2]

ArithUint256 & altintegration::ArithUint256::operator-= ( const ArithUint256 b)
inline

Definition at line 152 of file arith_uint256.hpp.

152 {
153 *this += -b;
154 return *this;
155 }

◆ operator-=() [2/2]

ArithUint256 & altintegration::ArithUint256::operator-= ( uint64_t  b64)
inline

Definition at line 164 of file arith_uint256.hpp.

164 {
165 ArithUint256 b;
166 b = b64;
167 *this += -b;
168 return *this;
169 }

◆ operator=()

ArithUint256 & altintegration::ArithUint256::operator= ( uint64_t  b)
inline

Definition at line 79 of file arith_uint256.hpp.

79 {
80 data_[0] = (uint8_t)b;
81 data_[1] = (uint8_t)(b >> 8);
82 data_[2] = (uint8_t)(b >> 16);
83 data_[3] = (uint8_t)(b >> 24);
84 data_[4] = (uint8_t)(b >> 32);
85 data_[5] = (uint8_t)(b >> 40);
86 data_[6] = (uint8_t)(b >> 48);
87 data_[7] = (uint8_t)(b >> 56);
88 for (int i = 8; i < SHA256_HASH_SIZE; i++) {
89 data_[i] = 0;
90 }
91 return *this;
92 }

◆ operator^=() [1/2]

ArithUint256 & altintegration::ArithUint256::operator^= ( const ArithUint256 b)
inline

Definition at line 94 of file arith_uint256.hpp.

94 {
95 for (int i = 0; i < SHA256_HASH_SIZE; i++) {
96 data_[i] ^= b.data_[i];
97 }
98 return *this;
99 }

◆ operator^=() [2/2]

ArithUint256 & altintegration::ArithUint256::operator^= ( uint64_t  b)
inline

Definition at line 115 of file arith_uint256.hpp.

115 {
116 data_[0] ^= (uint8_t)b;
117 data_[1] ^= (uint8_t)(b >> 8);
118 data_[2] ^= (uint8_t)(b >> 16);
119 data_[3] ^= (uint8_t)(b >> 24);
120 data_[4] ^= (uint8_t)(b >> 32);
121 data_[5] ^= (uint8_t)(b >> 40);
122 data_[6] ^= (uint8_t)(b >> 48);
123 data_[7] ^= (uint8_t)(b >> 56);
124 return *this;
125 }

◆ operator|=() [1/2]

ArithUint256 & altintegration::ArithUint256::operator|= ( const ArithUint256 b)
inline

Definition at line 108 of file arith_uint256.hpp.

108 {
109 for (int i = 0; i < SHA256_HASH_SIZE; i++) {
110 data_[i] |= b.data_[i];
111 }
112 return *this;
113 }

◆ operator|=() [2/2]

ArithUint256 & altintegration::ArithUint256::operator|= ( uint64_t  b)
inline

Definition at line 127 of file arith_uint256.hpp.

127 {
128 data_[0] |= (uint8_t)b;
129 data_[1] |= (uint8_t)(b >> 8);
130 data_[2] |= (uint8_t)(b >> 16);
131 data_[3] |= (uint8_t)(b >> 24);
132 data_[4] |= (uint8_t)(b >> 32);
133 data_[5] |= (uint8_t)(b >> 40);
134 data_[6] |= (uint8_t)(b >> 48);
135 data_[7] |= (uint8_t)(b >> 56);
136 return *this;
137 }

◆ operator~()

const ArithUint256 altintegration::ArithUint256::operator~ ( ) const
inline

Definition at line 62 of file arith_uint256.hpp.

62 {
63 ArithUint256 ret;
64 for (int i = 0; i < SHA256_HASH_SIZE; i++) {
65 ret.data_[i] = ~data_[i];
66 }
67 return ret;
68 }

Friends And Related Function Documentation

◆ operator&

const ArithUint256 operator& ( const ArithUint256 a,
const ArithUint256 b 
)
friend

Definition at line 237 of file arith_uint256.hpp.

238 {
239 return ArithUint256(a) &= b;
240 }

◆ operator* [1/2]

const ArithUint256 operator* ( const ArithUint256 a,
const ArithUint256 b 
)
friend

Definition at line 225 of file arith_uint256.hpp.

226 {
227 return ArithUint256(a) *= b;
228 }

◆ operator* [2/2]

const ArithUint256 operator* ( const ArithUint256 a,
uint32_t  b 
)
friend

Definition at line 253 of file arith_uint256.hpp.

254 {
255 return ArithUint256(a) *= b;
256 }

◆ operator+

const ArithUint256 operator+ ( const ArithUint256 a,
const ArithUint256 b 
)
friend

Definition at line 217 of file arith_uint256.hpp.

218 {
219 return ArithUint256(a) += b;
220 }

◆ operator-

const ArithUint256 operator- ( const ArithUint256 a,
const ArithUint256 b 
)
friend

Definition at line 221 of file arith_uint256.hpp.

222 {
223 return ArithUint256(a) -= b;
224 }

◆ operator/

const ArithUint256 operator/ ( const ArithUint256 a,
const ArithUint256 b 
)
friend

Definition at line 229 of file arith_uint256.hpp.

230 {
231 return ArithUint256(a) /= b;
232 }

◆ operator<

bool operator< ( const ArithUint256 a,
const ArithUint256 b 
)
friend

Definition at line 260 of file arith_uint256.hpp.

260 {
261 return a.compareTo(b) < 0;
262 }

◆ operator<<

const ArithUint256 operator<< ( const ArithUint256 a,
int  shift 
)
friend

Definition at line 249 of file arith_uint256.hpp.

250 {
251 return ArithUint256(a) <<= shift;
252 }

◆ operator<=

bool operator<= ( const ArithUint256 a,
const ArithUint256 b 
)
friend

Definition at line 266 of file arith_uint256.hpp.

266 {
267 return a.compareTo(b) <= 0;
268 }

◆ operator==

bool operator== ( const ArithUint256 a,
uint64_t  b 
)
friend

Definition at line 269 of file arith_uint256.hpp.

269 {
270 return a.compareTo(b) == 0;
271 }

◆ operator>

bool operator> ( const ArithUint256 a,
const ArithUint256 b 
)
friend

Definition at line 257 of file arith_uint256.hpp.

257 {
258 return a.compareTo(b) > 0;
259 }

◆ operator>=

bool operator>= ( const ArithUint256 a,
const ArithUint256 b 
)
friend

Definition at line 263 of file arith_uint256.hpp.

263 {
264 return a.compareTo(b) >= 0;
265 }

◆ operator>>

const ArithUint256 operator>> ( const ArithUint256 a,
int  shift 
)
friend

Definition at line 245 of file arith_uint256.hpp.

246 {
247 return ArithUint256(a) >>= shift;
248 }

◆ operator^

const ArithUint256 operator^ ( const ArithUint256 a,
const ArithUint256 b 
)
friend

Definition at line 241 of file arith_uint256.hpp.

242 {
243 return ArithUint256(a) ^= b;
244 }

◆ operator|

const ArithUint256 operator| ( const ArithUint256 a,
const ArithUint256 b 
)
friend

Definition at line 233 of file arith_uint256.hpp.

234 {
235 return ArithUint256(a) |= b;
236 }

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