long-integer

Long Division in Java not working as expected

删除回忆录丶 提交于 2019-12-05 05:50:46
class LongDiv{ public static void main(String [] args){ final long x = 24*60*60*1000*1000; final long y = 24*60*60*1000; System.out.println(x/y); } } although the expected answer is 1000, but the javac gives it as 5. Reason? The long x you are creating isn't the value you expected. It is in the integer range. To create longs, use: final long x = 24L*60L*60L*1000L*1000L; final long y = 24L*60L*60L*1000L; System.out.println(x/y); The x you computed, in the integer range, was 500654080 . This divided by the y ( = 86400000 ), results in 5.794607407407407... . Java truncates the decimal part which

Splitting a long page into a number of pages

穿精又带淫゛_ 提交于 2019-12-05 05:27:59
问题 I want to pull a dynamic content, which consists of a long text input with some images, into a div with a fixed width (300px) and height (1000px), the challenge is I cannot use overflow: auto in css when the content's length is exceeding the div's height (1000px), instead, I am asked to split the long content into pages with a pagination. Is it possible to achieve with PHP or do I have to use javascript (jquery)? I was thinking to count the number of characters and splitting them, but it

hibernate returning BigDecimal datatype instead of long

*爱你&永不变心* 提交于 2019-12-05 04:44:28
The hibernate named query returns a BigDecimal for a column that has datatype NUMBER. select col1 as "col1" from table1 union select col2 as "col1" from table2 On client side, I expect the datatype of col1 to be long (primitive) I do this: <return-scalar column="col1" type="java.lang.Long" /> or <return-scalar column="col1" type="long" /> In both cases, I get : java.lang.ClassCastException: java.math.BigDecimal incompatible with java.lang.Long How can I fix this? My suspiscion, something wrong with the aliasing? Oracle NUMBER maps to BigDecimal in Hibernate by default. Try setting the type to

What is the largest data type for storing (and printing) an integer?

孤人 提交于 2019-12-05 04:16:57
In C on a 32-bit system, which data type will store (and can therefore print) the largest integer? Is it long long or unsigned long ? Is there an unsigned long long ? And which is the most precise and politically correct? wnoise Your question is a bit unclear, but intmax_t is the largest signed integer-valued type (and uintmax_t is the largest unsigned integer type). These are typedefs defined in <stdint.h> , but if you are printing them, you need <inttypes.h> instead, and the PRInMAX macros for various values of n . Without beating around the bush I would like to say that sometimes not in

How to create a 64 bit Unique Integer in Java

╄→гoц情女王★ 提交于 2019-12-05 04:07:30
问题 I need to create a 64 bit unique integer in Java so that collision chances are low. The system is not distributed, so collisions between different computers are not a problem. Is there any way, we can create a 64 bit integer in Java which is always Unique? As of now I am using - long number = System.nanoTime(); Is this the right way to generate 64 bit Unique Integer in Java or is there anything else I can try? UPDATE:- How about doing this way? Will this be unique? UUID number = UUID

How do you get an unsigned long out of a string?

百般思念 提交于 2019-12-05 01:38:12
问题 What's the safest and best way to retrieve an unsigned long from a string in C++? I know of a number of possible methods. First, converting a signed long taken from atol. char *myStr; // Initalized to some value somehow. unsigned long n = ((unsigned)atol(myStr)); The obvious problem with this is, what happens when the value stored in myStr is larger than a signed long can contain? What does atol retrieve? The next possibility is to use strtoul. char *myStr; // Initalized to some value somehow

Java: many ways of casting a (long) Object to double

别说谁变了你拦得住时间么 提交于 2019-12-05 01:17:54
I have an Object obj that I know is actually a long . In some Math code I need it as double . Is it safe to directly cast it to double? double x = (double)obj; Or should I rather cast it first to long and then to double. double x = (double)(long)obj; I also found another (less readable) alternative: double x = new Long((long)obj).doubleValue(); What are the dangers/implications of doing either? Solution Summary : obj is a Number and not a long . Java 6 requires explicit casting, e.g.: double x = ((Number)obj).doubleValue() Java 7 has working cast magic: double x = (long)obj For more details on

How to convert two longs to a byte array = how to convert UUID to byte array?

只愿长相守 提交于 2019-12-05 00:32:21
I am using Javas UUID and need to convert a UUID to a byte Array. Strangely the UUID Class does not provide a "toBytes()" method. I already found out about the two methods: UUID.getMostSignificantBits() and UUID.getLeasSignificantBits() But how to get this into a byte array? the result should be a byte[] with those tow values. I somehow need to do Bitshifting but, how? update: I found: ByteBuffer byteBuffer = MappedByteBuffer.allocate(2); byteBuffer.putLong(uuid.getMostSignificantBits()); byteBuffer.putLong(uuid.getLeastSignificantBits()); Is this approach corret? Are there any other methods

Python: Is there a way to keep an automatic conversion from int to long int from happening?

試著忘記壹切 提交于 2019-12-04 23:48:03
Python is more strongly typed than other scripting languages. For example, in Perl: perl -E '$c=5; $d="6"; say $c+$d' #prints 11 But in Python: >>> c="6" >>> d=5 >>> print c+d Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: cannot concatenate 'str' and 'int' objects Perl will inspect a string and convert to a number, and the + - / * ** operators work as you expect with a number. PHP is similar. Python uses + to concatenate strings so the the attempted operation of c+d fails because c is a string, d an int. Python has stronger sense of numeric types than does

Java - parse and unsigned hex string into a signed long

て烟熏妆下的殇ゞ 提交于 2019-12-04 22:50:14
I have a bunch of hex strings, one of them, for example is: d1bc4f7154ac9edb which is the hex value of "-3333702275990511909". This is the same hex you get if you do Long.toHexString("d1bc4f7154ac9edb"); For now, let's just assume I only have access to the hex string values and that is it. Doing this: Long.parseLong(hexstring, 16); Doesn't work because it converts it to a different value that is too large for a Long. Is there away to convert these unsigned hex values into signed longs? Thanks! You can use BigInteger to parse it and get back a long : long value = new BigInteger(