From 07f6748c9ae255227903bde4fe359bc31c943494 Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Sun, 19 Nov 2017 13:13:32 +0100 Subject: Added the conversion from number to 64 bits integer Signed-off-by: Olivier Gayot --- number.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'number.cpp') diff --git a/number.cpp b/number.cpp index 75fd0f8..d39ed36 100644 --- a/number.cpp +++ b/number.cpp @@ -70,6 +70,26 @@ number::to_uint32() const return (*this == 0) ? 0 : _operands.front(); } +std::uint64_t +number::to_uint64() const +{ + auto size = _operands.size(); + + if (size > 2) { + throw std::out_of_range("> UINT64_MAX"); + } + + std::uint64_t result = 0; + + for (auto it = _operands.crbegin(); it != _operands.crend(); ++it) { + result <<= 32; + + result |= (*it); + } + + return result; +} + number::operator bool() const { return *this != 0; -- cgit v1.2.3