Why do these two multiplication operations give different results?

long oneYearWithL = 1000*60*60*24*365L; long oneYearWithoutL = 1000*60*60*24*365; Your first value is actually a long (Since 365L is a long, and 1000*60*60*24 is an integer, so the result of multiplying a long value with an integer value is a long value. But 2nd value is an integer (Since you are mulitplying an integer value with … Read more

How to use long id in Rails applications?

Credits to http://moeffju.net/blog/using-bigint-columns-in-rails-migrations class CreateDemo < ActiveRecord::Migration def self.up create_table :demo, :id => false do |t| t.integer :id, :limit => 8 end end end See the option :id => false which disables the automatic creation of the id field The t.integer :id, :limit => 8 line will produce a 64 bit integer field

Convert from Long to date format

You can use below line of code to do this. Here timeInMilliSecond is long value. String dateString = new SimpleDateFormat(“MM/dd/yyyy”).format(new Date(TimeinMilliSeccond)); Or you can use below code too also. String longV = “1343805819061”; long millisecond = Long.parseLong(longV); // or you already have long value of date, use this instead of milliseconds variable. String dateString = … Read more

node.js – Is there any proper way to parse JSON with large numbers? (long, bigint, int64)

Not with built-in JSON.parse. You’ll need to parse it manually and treat values as string (if you want to do arithmetics with them there is bignumber.js) You can use Douglas Crockford JSON.js library as a base for your parser. EDIT2 ( 7 years after original answer ) – it might soon be possible to solve … Read more

Convert long to byte array and add it to another array

There are multiple ways to do it: Use a ByteBuffer (best option – concise and easy to read): byte[] bytes = ByteBuffer.allocate(Long.SIZE / Byte.SIZE).putLong(someLong).array(); You can also use DataOutputStream (more verbose): ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); dos.writeLong(someLong); dos.close(); byte[] longBytes = baos.toByteArray(); Finally, you can do this manually (taken from … Read more