aboutsummaryrefslogtreecommitdiff
path: root/bigint.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'bigint.cpp')
-rw-r--r--bigint.cpp21
1 files changed, 10 insertions, 11 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<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();