long-integer

C#: How to convert long to ulong

安稳与你 提交于 2019-12-05 18:14:49
问题 If i try with BitConverter,it requires a byte array and i don't have that.I have a Int32 and i want to convert it to UInt32. In C++ there was no problem with that. 回答1: A simple cast is all you need. Since it's possible to lose precision doing this, the conversion is explicit. long x = 10; ulong y = (ulong)x; 回答2: Try: Convert.ToUInt32() 回答3: Int32 i = 17; UInt32 j = (UInt32)i; EDIT: question is unclear whether you have a long or an int? 回答4: Given this function: string test(long vLong) {

Accessing the highest digits of large numbers from Python long

岁酱吖の 提交于 2019-12-05 18:05:30
I'm working with numbers with tens of thousands of digits in python. The long type works beautifully in performing math on these numbers, however I'm unable to access the highest digits of these numbers in a sufficiently fast way. Note that I don't know exactly how many digits the number contains. The "highest digits" refers to the digits in the most significant place, the lowest digits can be accessed quickly using modulus. I can think of two ways to access these digits in python but they're both too slow for my purposes. I have tried converting to a string and accessing digits through array

Lucene LongField exact search with Query

↘锁芯ラ 提交于 2019-12-05 15:16:27
How can I use a TermQuery to exactly match a LongField? Consider the warning on the NumericUtils API NOTE: This API is for internal purposes only and might change in incompatible ways in the next release. I've noticed this becoming a problem for some people, since the NumericUtils API did indeed change significantly from Version 3.6 to Version 4.0 . I would recommend avoiding using it directly. Instead, use a NumericRangeQuery to search for numeric values. Precise matches can be obtained by setting maximum and minimum ranges to equal values. Also, deliberately selecting which fields should be

gcc, width of long int on different architectures

白昼怎懂夜的黑 提交于 2019-12-05 10:36:36
On 64-bit architectures, long int , according to gcc is at least an int64_t . On 32-bit, long int is at least int32_t . With Microsoft compilers, long is always an int32_t , regardless of 32/64-bit. Is there any way to: Force gcc to treat long as a int64_t, on 32bit? (for ease of testing) Force gcc to treat long as a int32_t on 64bit? (for compliance with MS's compiler). Don't do this - use standard types such as int32_t , uint32_t , int64_t , uint64_t , etc from <stdint.h> rather than trying to make assumptions about naked types such as long int or trying to bend the compiler to your will.

Python MySQLdb converters isn't working

 ̄綄美尐妖づ 提交于 2019-12-05 08:54:34
I'm trying to run an ETL script using python and MySQLdb but I'm stuck with the results from my initial extract query. The types returned are all Long and Decimal when I want Int and Float. I've searched around for a few hours trying to get an answer to this without any success. database = MySQLdb.connect(host='db',user='user', passwd='password', db='db123') database_cursor = database.cursor() database_query = ("SELECT id, siteId, campaignId, hour, sum(impressions) AS impressions, " "sum(clicks) AS clicks, sum(conversions) AS conversions, sum(costs/1000000) AS revenue " "FROM database.DM

How to find N longest lines in a text file and print them to stdout?

有些话、适合烂在心里 提交于 2019-12-05 08:49:46
The first line contains the value of the number 'N' followed by multiple lines. I could solve it in order of n^2 algorithm. Can someone suggest a better one? You can use a minimum-heap and do it in O(n*(log(N))): heap = new Min-Heap(N) foreach line in text: if length(line) > heap.min(): heap.pop() heap.insert(line) foreach line in heap: print to stdout: line. it could also be done in O(n) using Select(N) (which selects the Nth number) followed by partition around the Nth number (which arranges all the with size larger or equal to the Nth number to one side of it). i = Select(lines, N)

Converting a C byte array to a long long

依然范特西╮ 提交于 2019-12-05 08:36:45
I have an 8-byte array in my application with this data: 00000133339e36a2 This data represents a long (on the platform the data was written in, on a Mac this would be a long long) with the value of 1319420966562 In the actual application this is a semi-randomized set of data, so the number will always be different. Therefore, I need to convert the byte array into a printable long long. I've tried casting the data directly into a long long, but I came up with 1305392 where I should have been seeing the above number. For those of you with more experience in C byte manipulation than I do, how

Removing the .0 from a double

落爺英雄遲暮 提交于 2019-12-05 08:31:53
I am trying to display numbers in a string dynamically, so if the number has decimal's display them but if not don"t show the .0 example: display 5.5 as 5.5 and 5.0 as 5 This is what I have so far: (answer is a double) double temp = answer; long temp2 = (long) temp; if (temp == temp2) { output = String.valueOf(temp2); System.out.println(output); this work's fine up to about 1e18 then will error out because of the maximum size of a Long. So how would I achieve this on bigger numbers like 5.43e86 Kal Use DecimalFormat double answer = 5.0; DecimalFormat df = new DecimalFormat("###.#"); System.out

Alternative to BigInteger.ModPow(); in C#

半世苍凉 提交于 2019-12-05 08:04:45
问题 i'm looking for an alternative to the BigInteger package of C# which has been introduced with NET 4.x. The mathematical operations with this object are terribly slow, I guess this is caused by the fact that the arithmetics are done on a higher level than the primitive types - or badly optimized, whatever. Int64/long/ulong or other 64bit-numbers are way to small and won't calculate correctly - I'm talking about 64bit-integer to the power of 64-bit integers. Hopefully someone can suggest my

How to Convert Long to Guid and Vice Versa?

℡╲_俬逩灬. 提交于 2019-12-05 07:27:41
Is this even possible? I don't even think it is, but I saw some code that was trying to do it. However, my unit tests showed that it was not working. I did see some similar thoughts: Converting GUID to Integer and Back Converting System.Decimal to System.Guid Just for clarification. The Guid creation is outside of my control; therefore, I can't just store the value in one of the Guid sets. A GUID is 16 bytes long. A "long" is often understood as being 64 bits (i.e. 8 bytes) long. You cannot convert between those without losing or providing extra data. A GUID can never fit a long, because, as I