mawinkle 6 years ago
parent
commit
ccfc7ecd85
1 changed files with 45 additions and 0 deletions
  1. 45 0
      BigInt.hpp

+ 45 - 0
BigInt.hpp

@@ -113,9 +113,54 @@ struct BigInt{
 		ret.trim();
 		return ret;
 	}
+	
+	inline BigInt& bitshiftLeft(int c){
+		if(c < 0)return bitshiftRight(-c);
+		unsigned int jump = c / 32;
+		unsigned int sh = c % 32;
+		for(int i = 0;i < size() - jump;i++){
+			data[i] = l(data[i + jump] << sh);
+			if(i < size() - jump - 1){
+				data[i] |= data[i + jump + 1] >> (32 - sh);
+			}
+		}
+		//TODO: Set remaining bits to 0
+		return *this;
+	}
+	
+	inline BigInt& bitshiftRight(int c){
+		if(c < 0)return bitshiftLeft(-c);
+		unsigned int jump = c / 32;
+		unsigned int sh = c % 32;
+		for(unsigned int i = size() - 1;i >= jump;i--){
+			data[i] = data[i - jump] >> sh;
+			if(i > jump){
+				data[i] |= l(data[i - jump - 1] << (32 - sh));
+			}
+		}
+		//TODO: Set remaining bits to 0
+		return *this;
+	}
+	inline BigInt& chunkshiftLeft(int c){
+		if(c < 0)return chunkshiftRight(-c);
+		for(int i = 0;i < size() - c;i++){
+			data[i] = data[i] + c;
+		}
+		for(int i = size() - c;i < size();i++){
+			data[i] = 0;
+		}
+		return this;
+	}
+	
+	inline BigInt& chunkshiftRight(int c){
+		if(c < 0)return chunkshiftLeft(-c);
+		
+	}
+	
 	inline size_t size()const{
 		return data.size();
 	}
+	
 	inline bool isZero(){
 		for(uint64_t d : data){
 			if(d)return false;