From 98c5cb7a99222b3dc2d78468bd953a4a4a4142d7 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Thu, 6 Oct 2016 20:19:40 +0200 Subject: (de)serialise -> (de)serialiseMantissa --- bigint.cpp | 21 ++++++++++----------- bigint.h | 5 +++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/bigint.cpp b/bigint.cpp index 0827e1e..1f71cf9 100644 --- a/bigint.cpp +++ b/bigint.cpp @@ -523,28 +523,27 @@ bool Bigint::odd() const { return !even(); } -vector Bigint::serialise() const { - vector v(1+digits.size()*sizeof(digit_t)); - v[0]=sign; +string Bigint::serialiseMantissa() const { + string s; + s.resize(digits.size()*sizeof(digit_t)); int sz=digits.size(); for(int i=0;i>(8*j))&255; + s[i*sizeof(digit_t)+j]=(digits[i]>>(8*j))&255; } } - return v; + return s; } -void Bigint::deserialise(const vector &v){ - assert(v.size()%4==1); - sign=(int)v[0]; - assert(sign==1||sign==-1); - int sz=v.size()/4; +void Bigint::deserialiseMantissa(const string &s){ + assert(s.size()%4==0); + sign=1; + int sz=s.size()/4; digits.resize(sz); for(int i=0;i +#include #include #include #include @@ -86,8 +87,8 @@ public: bool even() const; bool odd() const; - std::vector serialise() const; - void deserialise(const std::vector&); + std::string serialiseMantissa() const; //stores everything but the sign + void deserialiseMantissa(const std::string&); //restores non-negative number std::vector bits() const; friend std::istream& operator>>(std::istream&,Bigint&); -- cgit v1.2.3-70-g09d2