long-integer

What is the difference between unsigned long and unsigned long long?

会有一股神秘感。 提交于 2019-12-04 14:57:02
I expected that the size will be different. But both are showing 8bytes. #include <iostream> using namespace std; int main() { cout<<"Size of long:"<<sizeof(unsigned long)<<"\n"; cout<<"Size of Long Long:"<< sizeof(unsigned long long)<<"\n"; } Output: Size of long:8 Size of Long Long:8 They're two distinct types, even if they happen to have the same size and representation in some particular implementation. unsigned long is required to be at least 32 bits. unsigned long long is required to be at least 64 bits. (Actually the requirements are stated in terms of the ranges of values they can

Average of 3 long integers

心已入冬 提交于 2019-12-04 07:27:18
问题 I have 3 very large signed integers. long x = long.MaxValue; long y = long.MaxValue - 1; long z = long.MaxValue - 2; I want to calculate their truncated average. Expected average value is long.MaxValue - 1 , which is 9223372036854775806 . It is impossible to calculate it as: long avg = (x + y + z) / 3; // 3074457345618258600 Note: I read all those questions about average of 2 numbers, but I don't see how that technique can be applied to average of 3 numbers. It would be very easy with the

Help me translate long value, expressed in hex, back in to a date/time

ぐ巨炮叔叔 提交于 2019-12-04 05:37:13
问题 I have a date value, which I'm told is 8 bytes, a single "long" (aka int64) value, and converted to hex: 60f347d15798c901 How can I convert this and values like this, using PHP, into a time/date? Converting it to decimal gives me: 96 243 71 209 87 152 201 1 A little more info: the original value is a C# DateTime, and should represent a time/date about 2 or 3 weeks ago. 回答1: (Thanks to thomasrutter's post, which gave me the Windows filetime epoch): The given date appears to be a Windows 64-bit

Why are there so many types of number in Java when long and double work every time?

廉价感情. 提交于 2019-12-04 05:31:27
问题 Now I have been trying to learn Java Programming, I want to know why do we use things like Float , short , and int when we could be just be using Long and Double ? I don't understand that part. 回答1: Great question, especially if you're coming from a language like JavaScript which does not make a distinction between types of numbers. Java is a bit more strict than those languages, and everything you write is first compiled to what is called byte code, which is sort of like assembly language,

Long polling in Laravel (sleep() function make application freeze)

最后都变了- 提交于 2019-12-04 04:45:39
I'm trying to program long polling functionality in Laravel, but when I use the sleep() function, the whole application freezes/blocks until the sleep() function is done. Does anyone know how to solve this problem? My javascript looks like this: function startRefresh() { longpending = $.ajax({ type: 'POST', url: '/getNewWords', data: { wordid: ""+$('.lastWordId').attr('class').split(' ')[1]+"" }, async: true, cache: false }).done(function(data) { $("#words").prepend(data); startRefresh(); }); } And the PHP: public function longPolling() { $time = time(); $wordid = Input::get('wordid'); session

parse long to negative number

元气小坏坏 提交于 2019-12-04 04:14:55
问题 code: public class Main{ public static void main(String[] a){ long t=24*1000*3600; System.out.println(t*25); System.out.println(24*1000*3600*25); } } This prints : 2160000000 -2134967296 Why? Thanks for all the replies. Is the only way to use L after the number? I have tried the (long)24*1000*3600*25 but this is also negative. 回答1: To explain it clearly, System.out.println(24*1000*3600*25); In the above statement are actually int literals. To make treat them as a long literal you need to

Converting a four character string to a long

落花浮王杯 提交于 2019-12-04 04:02:17
问题 I want to convert a four character string (i.e. four characters) into a long (i.e. convert them to ASCII codes and then put them into the long). As I understand it, this is done by writing the first character to the first byte of the long, the second to the adjacent memory location, and so on. But I don't know how to do this in C++. Can someone please point me in the right direction? Thanks in advance. 回答1: Here's your set of four characters: const unsigned char buf[4] = { 'a', '0', '%', 'Q'

C#: How to convert long to ulong

六月ゝ 毕业季﹏ 提交于 2019-12-04 02:21:54
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. 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; Try: Convert.ToUInt32() Int32 i = 17; UInt32 j = (UInt32)i; EDIT: question is unclear whether you have a long or an int? Given this function: string test(long vLong) { ulong vULong = (ulong)vLong; return string.Format("long hex: {0:X}, ulong hex: {1:X}", vLong, vULong); } And this usage:

Parse JSON with large numbers javascript

我的梦境 提交于 2019-12-04 01:52:50
问题 I'm getting a JSON object that includes a long type value from an API response. Since javascript can't handle 64bit numbers, when executing JSON.parse on the response it rounds the number to the maximum value javascript can handle. API response: { "subject": "subjectTitle", "longNumberKey": 7356270823847851521, } When parsing this object to JSON , longNumberKey value would be 7356270823847852000 instead of 7356270823847851521 . A solution would be to represent this value as a string but I can

What is the historical context for long and int often being the same size?

被刻印的时光 ゝ 提交于 2019-12-04 01:28:31
问题 According to numerous answers here, long and int are both 32 bits in size on common platforms in C and C++ (Windows & Linux, 32 & 64 bit.) (I'm aware that there is no standard, but in practice, these are the observed sizes.) So my question is, how did this come about? Why do we have two types that are the same size? I previously always assumed long would be 64 bits most of the time, and int 32. I'm not saying it "should" be one way or the other, I'm just curious as to how we got here. 回答1: