6#ifndef ALT_INTEGRATION_VERIBLOCK_ARITH_UINT256_HPP
7#define ALT_INTEGRATION_VERIBLOCK_ARITH_UINT256_HPP
20#include "veriblock/pop/assert.hpp"
25class uint_error :
public std::runtime_error {
27 explicit uint_error(
const std::string& str) : std::runtime_error(str) {}
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);
65 ret.data_[i] = ~data_[i];
73 ret.data_[i] = ~data_[i];
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);
96 data_[i] ^= b.data_[i];
103 data_[i] &= b.data_[i];
110 data_[i] |= b.data_[i];
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);
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);
145 uint64_t n = carry + data_[i] + b.data_[i];
192 --data_[i] == (std::numeric_limits<uint8_t>::max)();
213 std::string toString()
const;
225 friend inline const ArithUint256 operator*(
const ArithUint256& a,
226 const ArithUint256& b) {
227 return ArithUint256(a) *= b;
229 friend inline const ArithUint256 operator/(
const ArithUint256& a,
230 const ArithUint256& b) {
231 return ArithUint256(a) /= b;
233 friend inline const ArithUint256 operator|(
const ArithUint256& a,
234 const ArithUint256& b) {
235 return ArithUint256(a) |= b;
237 friend inline const ArithUint256 operator&(
const ArithUint256& a,
238 const ArithUint256& b) {
239 return ArithUint256(a) &= b;
241 friend inline const ArithUint256 operator^(
const ArithUint256& a,
242 const ArithUint256& b) {
243 return ArithUint256(a) ^= b;
245 friend inline const ArithUint256 operator>>(
const ArithUint256& a,
247 return ArithUint256(a) >>= shift;
249 friend inline const ArithUint256 operator<<(
const ArithUint256& a,
251 return ArithUint256(a) <<= shift;
253 friend inline const ArithUint256 operator*(
const ArithUint256& a,
255 return ArithUint256(a) *= b;
257 friend inline bool operator>(
const ArithUint256& a,
const ArithUint256& b) {
258 return a.compareTo(b) > 0;
260 friend inline bool operator<(
const ArithUint256& a,
const ArithUint256& b) {
261 return a.compareTo(b) < 0;
263 friend inline bool operator>=(
const ArithUint256& a,
const ArithUint256& b) {
264 return a.compareTo(b) >= 0;
266 friend inline bool operator<=(
const ArithUint256& a,
const ArithUint256& b) {
267 return a.compareTo(b) <= 0;
269 friend inline bool operator==(
const ArithUint256& a, uint64_t b) {
270 return a.compareTo(b) == 0;
282 std::string toHex()
const;
284 uint64_t getLow64()
const;
287 bool* negative =
nullptr,
288 bool* overflow =
nullptr);
290 uint32_t toBits(
bool negative =
false)
const;
292 void setHex(
const std::string& value);
256-bit unsigned big integer.
static ArithUint256 fromHex(const std::string &hex)
unsigned int bits() const
Returns the position of the highest bit set plus one, or zero if the value is zero.
All constants in alt-cpp.
constexpr const auto SHA256_HASH_SIZE
sha256 hash size
void PrintTo(const ArithUint256 &uint, ::std::ostream *os)
custom gtest printer, which prints Blob of any size as hexstring @ private
Contiguous byte array of fixed size.