59 for(std::size_t i=0; i<n.size(); i++)
60 if(!(isalnum(n[i]) || (n[i]==
'-' && i==0)))
74 bool neg=a.is_negative();
82 std::size_t len = a.digits(2) + 2;
83 std::vector<char> buffer(len);
84 char *s = a.as_string(buffer.data(), len, 2);
86 std::string result(s);
88 if(result.size()<width)
91 fill.resize(width-result.size(),
'0');
94 else if(result.size()>width)
95 result=result.substr(result.size()-width, width);
99 for(std::size_t i=0; i<result.size(); i++)
100 result[i]=(result[i]==
'0')?
'1':
'0';
108 unsigned len = n.digits(base) + 2;
109 std::vector<char> buffer(len);
110 char *s = n.as_string(buffer.data(), len, base);
112 std::string result(s);
125 if(n.size()<=(
sizeof(
unsigned long)*8))
129 unsigned long mask=1;
130 mask=mask << (n.size()-1);
135 unsigned long other_bits=0;
137 for(std::string::const_iterator it=++n.begin();
149 return top_bit+other_bits;
155 mask=mask << (n.size()-1);
161 for(std::string::const_iterator it=++n.begin();
174 if(n.find_first_not_of(
"01")!=std::string::npos)
184 return BigInt(n.c_str(), 2);
197 PRECONDITION(n>=0 && n<=std::numeric_limits<std::size_t>::max());
200 return (std::size_t) ull;
205 PRECONDITION(n>=0 && n<=std::numeric_limits<unsigned>::max());
208 return (
unsigned)ull;
218 std::function<
bool(
bool,
bool)> f)
220 const auto digits = std::max(a.digits(2), b.digits(2));
225 for(std::size_t i = 0; i < digits; i++)
227 const bool bit_a = tmp_a.is_odd();
228 const bool bit_b = tmp_b.is_odd();
229 const bool bit_result = f(bit_a, bit_b);
231 result +=
power(2, i);
245 if(a.is_ulong() && b.is_ulong())
246 return a.to_ulong() | b.to_ulong();
248 return bitwise(a, b, [](
bool a,
bool b) {
return a || b; });
257 if(a.is_ulong() && b.is_ulong())
258 return a.to_ulong() & b.to_ulong();
260 return bitwise(a, b, [](
bool a,
bool b) {
return a && b; });
269 if(a.is_ulong() && b.is_ulong())
270 return a.to_ulong() ^ b.to_ulong();
272 return bitwise(a, b, [](
bool a,
bool b) {
return a != b; });
281 std::size_t true_size)
288 llong_t result=a.to_long()<<shift;
290 true_size<(
sizeof(
llong_t)*8) ?
291 (1LL << true_size) - 1 :
302 std::size_t true_size)
309 const llong_t sign = (1LL << (true_size - 1)) & number;
310 const llong_t pad = (sign == 0) ? 0 : ~((1LL << (true_size - shift)) - 1);
321 std::size_t true_size)
327 llong_t result=a.to_long()<<shift;
328 if(true_size<(
sizeof(
llong_t)*8))
330 const llong_t sign = (1LL << (true_size - 1)) & result;
331 const llong_t mask = (1LL << true_size) - 1;
347 std::size_t true_size)
363 std::size_t true_size)
372 const ullong_t filter = 1ULL << (true_size - 1);
373 ullong_t result=(number >> shift)|((number<<revShift)&filter);
383 std::size_t true_size)
392 const ullong_t filter = 1ULL << (true_size - 1);
393 ullong_t result=((number<<shift)&filter)|((number&filter) >> revShift);
bool is_signed(const typet &t)
Convenience function – is the type signed?
mp_integer rotate_left(const mp_integer &a, const mp_integer &b, std::size_t true_size)
rotate left (LSB=MSB) bitwise operations only make sense on native objects, hence the largest object ...
const mp_integer string2integer(const std::string &n, unsigned base)
const std::string integer2string(const mp_integer &n, unsigned base)
mp_integer::ullong_t integer2ulong(const mp_integer &n)
mp_integer bitwise_xor(const mp_integer &a, const mp_integer &b)
bitwise 'xor' of two nonnegative integers
const mp_integer binary2integer(const std::string &n, bool is_signed)
convert binary string representation to mp_integer
mp_integer arith_left_shift(const mp_integer &a, const mp_integer &b, std::size_t true_size)
arithmetic left shift bitwise operations only make sense on native objects, hence the largest object ...
mp_integer logic_left_shift(const mp_integer &a, const mp_integer &b, std::size_t true_size)
logic left shift bitwise operations only make sense on native objects, hence the largest object size ...
static struct_typet::componentst::iterator pad(struct_typet::componentst &components, struct_typet::componentst::iterator where, std::size_t pad_bits)
mp_integer operator<<(const mp_integer &a, const mp_integer &b)
mp_integer logic_right_shift(const mp_integer &a, const mp_integer &b, std::size_t true_size)
logic right shift (loads 0 on MSB) bitwise operations only make sense on native objects,...
mp_integer bitwise_and(const mp_integer &a, const mp_integer &b)
bitwise 'and' of two nonnegative integers
mp_integer arith_right_shift(const mp_integer &a, const mp_integer &b, std::size_t true_size)
arithmetic right shift (loads sign on MSB) bitwise operations only make sense on native objects,...
mp_integer operator>>(const mp_integer &a, const mp_integer &b)
#define PRECONDITION(CONDITION)
mp_integer rotate_right(const mp_integer &a, const mp_integer &b, std::size_t true_size)
rotates right (MSB=LSB) bitwise operations only make sense on native objects, hence the largest objec...
mp_integer bitwise_or(const mp_integer &a, const mp_integer &b)
bitwise 'or' of two nonnegative integers
unsigned integer2unsigned(const mp_integer &n)
BigInt::ullong_t ullong_t
const std::string integer2binary(const mp_integer &n, std::size_t width)
mp_integer bitwise(const mp_integer &a, const mp_integer &b, std::function< bool(bool, bool)> f)
bitwise binary operation over two integers, given as a functor
std::size_t integer2size_t(const mp_integer &n)