biginteger

Shifting big numbers

こ雲淡風輕ζ 提交于 2019-12-11 11:29:10
问题 X = 712360810625491574981234007851998 is represented using a linked list and each node is an unsigned int Is there a fast way to do X << 8 X << 591 other than X * 2^8 X * 2^591 ? 回答1: Bit shifting is very easy in any arbitrary number of bits. Just remember to shift the overflowed bits to the next element. That's all Below is a left shift by 3 example uint64_t i1, i2, i3, o1, o2, o3; // {o3, o2, o1} = {i3, i2, i1} << 3; o3 = i3 << 3 | i2 >> (32 - 3); o2 = i2 << 3 | i1 >> (32 - 3); o1 = i1 << 3

Java: BigInteger floor and ceil functions [closed]

回眸只為那壹抹淺笑 提交于 2019-12-11 11:28:59
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . I'm trying to implement an RSA attack in Java and I need to compute math operations like floor and ceil to BigInteger variables. As we know math.ceil and math.floor only apply to double variables, do you know any

How can I keep 1 million digit in Java?

耗尽温柔 提交于 2019-12-11 11:07:48
问题 My question is that, I want to multiply 2 number which has 1 million digit. When I tried to assign 1 million number to BigInteger, Compiler is giving to me error. The error is that:"constant string too long". 回答1: BigInteger is indeed the way to store such large integers, although hundreds or a few thousands of digits are more typical use cases. However, Java class files have limitations that won't allow hard coding a literal number that large. Instead, store the number in a file and read it

LargeInteger's equivalent of BigInteger's testBit?

匆匆过客 提交于 2019-12-11 10:30:00
问题 Does LargeInteger have an equivalent to BigInteger's testBit? If not, how can testBit be performed on a LargeInteger ? I don't yet have the necessary skills to reproduce ((this & (1<<n)) != 0) . I tried making a method by just copying & pasting the above code referenced from the docs: static boolean testBit(int n){ return ((this & (1<<n)) != 0); } However, the compiler reports: error: non-static variable this cannot be referenced from a static context return ((this & (1<<n)) != 0); ^ error:

How to convert locale formatted number to BigInteger in Java?

心已入冬 提交于 2019-12-11 09:49:45
问题 I searched a lot but nothing helped me :( Suppose I need convert 12.090.129.019.201.920.192.091.029.102.901.920.192.019.201.920 (in Portuguese group separator: .) to BigInteger value. How to do that conversion? I tried use NumberFormat, DecimalFormat and nothing works or I didn't on right way :( 回答1: Get a NumberFormat instance for a Portuguese Locale, and then parse the number with it. This will also handle locale-specific decimal separators. NumberFormat nf = NumberFormat.getNumberInstance

C: print a BigInteger in base 10

旧街凉风 提交于 2019-12-11 09:46:35
问题 I am using this struct to represent 128bit integers: typedef struct { uint64_t low, high; } uint128; (Unless you can point me to a fast 128bit integer library I can not change that) Now I want to print such a value in base 10, using printf . I probably need division by 10 to do that, but no division is implemented yet. How can I do this? The solution does not have to be super efficient, as long as it works. EDIT: I like all solutions you came up with. You are awesome. 回答1: void printu128

As3 BigInteger returns an Incorrect Answer

ⅰ亾dé卋堺 提交于 2019-12-11 08:55:26
问题 I am trying to implement a RSA encryption program in flash. I looked into working with Big Numbers and found the BigInteger var type in the Crypto package. I started playing around with BigIntegers but my outputs are never the correct answer. For example the below code will output 5911 when the answer should be 9409. Any input about this error would be great. var temp:BigInteger = new BigInteger(String(97)); temp = temp.pow(2); trace(temp.toString()); Output = 5911 回答1: I'm not sure which

Can I raise a Java BigInteger to a double/float power?

折月煮酒 提交于 2019-12-11 08:48:47
问题 I'm a .NET developer, but apparently no library exists to do this in .NET. So, is there any BigInteger implementation in Java that allows raising a BigInteger to a double exponent: BigInteger result = BigInteger.pow( base, dblExponent); // Base is a BigInteger, dblExponent is a double. 回答1: try this: BigInteger base = new BigInteger("10"); double base1 = base.doubleValue(); double dblExponent = 10; double res = pow(base1, dblExponent); BigDecimal result = new BigDecimal(res); but pay

Python Random choice with 'percentage'

て烟熏妆下的殇ゞ 提交于 2019-12-11 08:41:19
问题 Foreword It looks like it is a duplicate of few stackoverflow question but my situation is (probably) slightly unique. My situation I have a dictionary. The key is a string and the value is an integer . I want the python script to randomly choose N number of keys . The value is how likely it is to be chosen. The higher the key's value is, the higher the chance the key will be randomly chosen. My solution So using some other StackOverflow post and the power of the internet I managed to solve

BigInteger Modulo '%' Operation & Less Than / More Than Operations

旧街凉风 提交于 2019-12-11 07:57:20
问题 Hi I have an algorithm in which I need to apply operations to BigInt's. I understand that BigInt's can be manipulated using the Maths class such as: import java.math.*; BigInteger a; BigInteger b = BigInteger.ZERO; BigInteger c = BigInteger.ONE; BigInteger d = new BigInteger ("3"); BigInteger e = BigInteger.valueOf(5); a.multiply(b); a.add(b); a.substract(b); a.divide(b); I need to be able to apply greater than for a while condition e.g. while (a > 0) { Which gives me a syntax error saying