long-integer

Why is the sizeof(int) == sizeof(long)?

こ雲淡風輕ζ 提交于 2019-12-30 08:07:12
问题 In the program listed below, the sizeof(int) and sizeof(long) are equal on my machine (both equal 4 bytes (or 32 bits)). A long, as far as I know, is 8 bytes. Is this correct? I have a 64-bit machine #include <stdio.h> #include <limits.h> int main(void){ printf("sizeof(short) = %d\n", (int)sizeof(short)); printf("sizeof(int) = %d\n", (int)sizeof(int)); printf("sizeof(long) = %d\n", (int)sizeof(long)); printf("sizeof(float) = %d\n", (int)sizeof(float)); printf("sizeof(double) = %d\n", (int

Hibernate returns BigIntegers instead of longs

喜夏-厌秋 提交于 2019-12-30 08:00:23
问题 This is my Sender entity @Entity public class Sender { @Id @GeneratedValue(strategy = GenerationType.AUTO) private long senderId; ... ... public long getSenderId() { return senderId; } public void setSenderId(long senderId) { this.senderId = senderId; } } When I try to execute following query: StringBuilder query = new StringBuilder(); query.append("Select sender.* "); query.append("From sender "); query.append("INNER JOIN coupledsender_subscriber "); query.append("ON coupledsender_subscriber

Convert python long/int to fixed size byte array

陌路散爱 提交于 2019-12-29 03:17:05
问题 I'm trying to implement RC4 and DH key exchange in python. Problem is that I have no idea about how to convert the python long/int from the key exchange to the byte array I need for the RC4 implementation. Is there a simple way to convert a long to the required length byte array? Update : forgot to mention that the numbers I'm dealing with are 768 bit unsigned integers. 回答1: I haven't done any benchmarks, but this recipe "works for me". The short version: use '%x' % val , then unhexlify the

Possible lossy conversion from long to int, JAVA

佐手、 提交于 2019-12-29 01:02:13
问题 I am trying to pass long value to the method and use it there to create a Long Array. However, I am getting "possible lossy conversion from long to int" error while creating an array long[] array = new long[n]; although I have not used any integers values. import java.util.Scanner; import java.util.ArrayList; public class test{ public static void main(String[] args){ Scanner input = new Scanner(System.in); long n = input.nextLong(); System.out. although("result is " + n + " is " + testing(n))

Warning: this decimal constant is unsigned only in ISO C90

早过忘川 提交于 2019-12-28 05:21:06
问题 Piece of code : long rangeVar = 0; rangeVar = atol(p_value); if (rangeVar >= -2147483648 && rangeVar <= 2147483647) On compiling I get: warning: this decimal constant is unsigned only in ISO C90 Thanks in Advance 回答1: The rules for the types of decimal integer constants changed between the 1990 and 1999 editions of the ISO C standard. In the 1990 version, an unsuffixed decimal integer constant's type is the first of int , long int , or unsigned long int in which its value can be represented.

Why can't your switch statement data type be long, Java?

青春壹個敷衍的年華 提交于 2019-12-28 03:31:17
问题 Here's an excerpt from Sun's Java tutorials: A switch works with the byte , short , char , and int primitive data types. It also works with enumerated types (discussed in Classes and Inheritance) and a few special classes that "wrap" certain primitive types: Character , Byte , Short , and Integer (discussed in Simple Data Objects). There must be a good reason why the long primitive data type is not allowed. Anyone know what it is? 回答1: I think to some extent it was probably an arbitrary

What is the maximum float in Python?

自古美人都是妖i 提交于 2019-12-27 11:38:28
问题 I think the maximum integer in python is available by calling sys.maxint . What is the maximum float or long in Python? 回答1: For float have a look at sys.float_info: >>> import sys >>> sys.float_info sys.floatinfo(max=1.7976931348623157e+308, max_exp=1024, max_10_exp=308, min=2.2 250738585072014e-308, min_exp=-1021, min_10_exp=-307, dig=15, mant_dig=53, epsil on=2.2204460492503131e-16, radix=2, rounds=1) Specifically, sys.float_info.max : >>> sys.float_info.max 1.7976931348623157e+308 If that

Java: random long number in 0 <= x < n range

那年仲夏 提交于 2019-12-27 11:11:23
问题 Random class has a method to generate random int in a given range. For example: Random r = new Random(); int x = r.nextInt(100); This would generate an int number more or equal to 0 and less than 100. I'd like to do exactly the same with long number. long y = magicRandomLongGenerator(100); Random class has only nextLong(), but it doesn't allow to set range. 回答1: Starting from Java 7 (or Android API Level 21 = 5.0+) you could directly use ThreadLocalRandom.current().nextLong(n) (for 0 ≤ x < n)

Issue Converting seconds to HH:MM:SS java

孤街醉人 提交于 2019-12-25 01:45:18
问题 I have a long variable which represents the downtime of an application in seconds. I want to display the downtime as HH:mm:ss Long downTime = 755; Date newD = new Date(downTime * 1000); When passing the long variable to the Date I multiplied it 1000 to get the millisecond value. The newD variable evaluates to Thu Jan 01 01:12:35 GMT 1970 The value of newD is off by 1 hour, 755 seconds is = 00:12:35 It was my understanding that seconds * 1000 = milliseconds will evaluate to the correct answer.

Is this an overflow?

孤街醉人 提交于 2019-12-25 00:33:36
问题 I have this segment of code: struct timeval start, end; gettimeofday(&start, NULL); //code I'm timing gettimeofday(&end, NULL); long elapsed = ((end.tv_sec-start.tv_sec)*1000000 + end.tv_usec-start.tv_usec); ofstream timeFile; timeFile.open ("timingSheet.txt"); timeFile << fixed << showpoint; timeFile << setprecision(2); timeFile << "Duration: " << elapsed << "\n"; timeFile.close(); Which will output the number of microseconds that has passed. However, if I change this line long elapsed = (