2017-08-06 46 views
0

我是新的C++ boost庫。我想在cpp_int類型上使用按位運算。下面的代碼工作正常。使用C++ boost庫的按位操作

#include <boost/multiprecision/cpp_int.hpp> 
#include <iostream> 
namespace mp = boost::multiprecision; 
using boost::multiprecision::cpp_int; 
using namespace std; 

int main(){ 
    cpp_int p = 2; 
    cout<<mp::pow(p, 1024)<<endl; 

    return 0; 
} 

然而,當我嘗試從用戶採取移值,我在(p<<c)線得到一個「無匹配的運營商< <」的錯誤。

#include <boost/multiprecision/cpp_int.hpp> 
#include <iostream> 
namespace mp = boost::multiprecision; 
using boost::multiprecision::cpp_int; 
using namespace std; 

int main(){ 
    cpp_int p = 2, c; 
    //cout<<mp::pow(p, 1024)<<endl; 
    cin>>c; 
    cout << (p<<c) << endl; 

    return 0; 
} 

回答

2

按位移僅在Boost Multiprecision中實現,當右側是內置整型時。你可以看到,在這裏:

http://www.boost.org/doc/libs/1_64_0/boost/multiprecision/number.hpp

所以,你可以在一個循環中使用uint64_t,每個時移高達UINT64_MAX,和遞減c,當您去。據推測,你不需要移動超過幾個bazillion數字。