diff options
author | tomsmeding <tom.smeding@gmail.com> | 2016-10-06 20:19:40 +0200 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2016-10-06 20:19:40 +0200 |
commit | 98c5cb7a99222b3dc2d78468bd953a4a4a4142d7 (patch) | |
tree | 79a0ea6005d3034902ef982a2d4f23b5f37f3182 | |
parent | 8e7f8300f82f9d93f94813cd717bf2943e5ad07a (diff) |
(de)serialise -> (de)serialiseMantissa
-rw-r--r-- | bigint.cpp | 21 | ||||
-rw-r--r-- | bigint.h | 5 |
2 files changed, 13 insertions, 13 deletions
@@ -523,28 +523,27 @@ bool Bigint::odd() const { return !even(); } -vector<char> Bigint::serialise() const { - vector<char> 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<sz;i++){ for(int j=0;j<(int)sizeof(digit_t);j++){ - v[1+i*sizeof(digit_t)+j]=(digits[i]>>(8*j))&255; + s[i*sizeof(digit_t)+j]=(digits[i]>>(8*j))&255; } } - return v; + return s; } -void Bigint::deserialise(const vector<char> &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<sz;i++){ digits[i]=0; for(int j=0;j<(int)sizeof(digit_t);j++){ - digits[i]|=v[1+i*sizeof(digit_t)+j]<<(8*j); + digits[i]|=s[i*sizeof(digit_t)+j]<<(8*j); } } shrink(); @@ -1,6 +1,7 @@ #pragma once #include <iostream> +#include <string> #include <vector> #include <utility> #include <cstdint> @@ -86,8 +87,8 @@ public: bool even() const; bool odd() const; - std::vector<char> serialise() const; - void deserialise(const std::vector<char>&); + std::string serialiseMantissa() const; //stores everything but the sign + void deserialiseMantissa(const std::string&); //restores non-negative number std::vector<bool> bits() const; friend std::istream& operator>>(std::istream&,Bigint&); |