56 for(std::size_t i=0; i<n.size(); i++)
57 if(!(
isalnum(n[i]) || (n[i]==
'-' && i==0)))
71 bool neg=a.is_negative();
79 std::size_t len = a.digits(2) + 2;
80 std::vector<char> buffer(len);
81 char *s = a.as_string(buffer.data(), len, 2);
83 std::string result(s);
85 if(result.size()<width)
88 fill.resize(width-result.size(),
'0');
91 else if(result.size()>width)
92 result=result.substr(result.size()-width, width);
96 for(std::size_t i=0; i<result.size(); i++)
97 result[i]=(result[i]==
'0')?
'1':
'0';
105 unsigned len = n.digits(base) + 2;
106 std::vector<char> buffer(len);
107 char *s = n.as_string(buffer.data(), len, base);
109 std::string result(s);
122 if(n.size() <= (
sizeof(
unsigned long) * CHAR_BIT))
126 unsigned long mask=1;
127 mask=mask << (n.size()-1);
132 unsigned long other_bits=0;
134 for(std::string::const_iterator it=++n.begin();
146 return top_bit+other_bits;
152 mask=mask << (n.size()-1);
158 for(std::string::const_iterator it=++n.begin();
171 if(n.find_first_not_of(
"01")!=std::string::npos)
181 return BigInt(n.c_str(), 2);
193 std::function<
bool(
bool,
bool)> f)
195 const auto digits = std::max(a.digits(2), b.digits(2));
200 for(std::size_t i = 0; i < digits; i++)
202 const bool bit_a = tmp_a.is_odd();
203 const bool bit_b = tmp_b.is_odd();
204 const bool bit_result = f(bit_a, bit_b);
206 result +=
power(2, i);
220 if(a.is_ulong() && b.is_ulong())
221 return a.to_ulong() | b.to_ulong();
223 return bitwise(a, b, [](
bool a,
bool b) {
return a || b; });
232 if(a.is_ulong() && b.is_ulong())
233 return a.to_ulong() & b.to_ulong();
235 return bitwise(a, b, [](
bool a,
bool b) {
return a && b; });
244 if(a.is_ulong() && b.is_ulong())
245 return a.to_ulong() ^ b.to_ulong();
247 return bitwise(a, b, [](
bool a,
bool b) {
return a != b; });
256 std::size_t true_size)
263 llong_t result=a.to_long()<<shift;
265 true_size < (
sizeof(
llong_t) * CHAR_BIT) ? (1LL << true_size) - 1 : -1;
275 std::size_t true_size)
282 const llong_t sign = (1LL << (true_size - 1)) & number;
283 const llong_t pad = (sign == 0) ? 0 : ~((1LL << (true_size - shift)) - 1);
294 std::size_t true_size)
300 llong_t result=a.to_long()<<shift;
301 if(true_size < (
sizeof(
llong_t) * CHAR_BIT))
303 const llong_t sign = (1LL << (true_size - 1)) & result;
304 const llong_t mask = (1LL << true_size) - 1;
320 std::size_t true_size)
336 std::size_t true_size)
345 const ullong_t filter = 1ULL << (true_size - 1);
346 ullong_t result=(number >> shift)|((number<<revShift)&filter);
356 std::size_t true_size)
365 const ullong_t filter = 1ULL << (true_size - 1);
366 ullong_t result=((number<<shift)&filter)|((number&filter) >> revShift);
const mp_integer binary2integer(const std::string &n, bool is_signed)
convert binary string representation to mp_integer
const mp_integer string2integer(const std::string &n, unsigned base)
BigInt::ullong_t ullong_t
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 operator>>(const mp_integer &a, const mp_integer &b)
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 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 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 ...
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...
const std::string integer2string(const mp_integer &n, unsigned base)
mp_integer bitwise_and(const mp_integer &a, const mp_integer &b)
bitwise 'and' of two nonnegative integers
mp_integer bitwise_or(const mp_integer &a, const mp_integer &b)
bitwise 'or' of two nonnegative integers
mp_integer bitwise_xor(const mp_integer &a, const mp_integer &b)
bitwise 'xor' of two nonnegative integers
mp_integer operator<<(const mp_integer &a, const mp_integer &b)
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
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 std::string integer2binary(const mp_integer &n, std::size_t width)
static struct_typet::componentst::iterator pad(struct_typet::componentst &components, struct_typet::componentst::iterator where, std::size_t pad_bits)
#define PRECONDITION(CONDITION)
bool is_signed(const typet &t)
Convenience function – is the type signed?