Skip to content

Commit

Permalink
Add conversion functions arith_uint256<->uint_256
Browse files Browse the repository at this point in the history
  • Loading branch information
laanwj committed Jan 5, 2015
1 parent bfc6070 commit 92cdb1a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/arith_uint256.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "arith_uint256.h"

#include "uint256.h"
#include "utilstrencodings.h"

#include <stdio.h>
Expand Down Expand Up @@ -355,3 +356,18 @@ uint64_t arith_uint256::GetHash(const arith_uint256& salt) const

return ((((uint64_t)b) << 32) | c);
}

uint256 ArithToUint256(const arith_uint256 &a)
{
uint256 b;
// TODO: needs bswap32 on big-endian
memcpy(b.begin(), a.pn, a.size());
return b;
}
arith_uint256 UintToArith256(const uint256 &a)
{
arith_uint256 b;
// TODO: needs bswap32 on big-endian
memcpy(b.pn, a.begin(), a.size());
return b;
}
8 changes: 8 additions & 0 deletions src/arith_uint256.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include <string>
#include <vector>

class uint256;

class uint_error : public std::runtime_error {
public:
explicit uint_error(const std::string& str) : std::runtime_error(str) {}
Expand Down Expand Up @@ -345,6 +347,12 @@ class arith_uint256 : public base_uint<256> {
uint32_t GetCompact(bool fNegative = false) const;

uint64_t GetHash(const arith_uint256& salt) const;

friend uint256 ArithToUint256(const arith_uint256 &);
friend arith_uint256 UintToArith256(const uint256 &);
};

uint256 ArithToUint256(const arith_uint256 &);
arith_uint256 UintToArith256(const uint256 &);

#endif // BITCOIN_UINT256_H

0 comments on commit 92cdb1a

Please sign in to comment.