0

NOTE: I need to do bitwise masking on the 64 bit integer.

I am converting some c# to javascript.

Within it is a ulong; a unsigned 64 bit c# integer.

The 64 bit integer is in a text based ascii file, which needs to be loaded into the javascript and processed. (I know how to load the file, I just need to be able for javascript to unserstand and be able to operate on these 64 bit integers without any loss.)

So how can I (accurately) store and work on this unsigned 64 bit integer in javascript?

Notes: I know javascript has no concept of ints, longs etc. But I am converting from c# where there is a 64 bit integer in a text file I load, and I need javascript to understand and be able to work on it without loss. (Ie, javascript only goes up to 53 bits with preceision, as far as I am aware.)

Rewind
  • 2,554
  • 3
  • 30
  • 56
  • Can you please clarify that you really mean JavaScript and not Java? There is no concept of signed/unsigned long/short integers in JavaScript. – Cᴏʀʏ Jun 13 '16 at 21:38
  • Yes, definitely javascript. It is within an html file. I know javascript has no concept. – Rewind Jun 13 '16 at 21:39
  • Possibly a duplicate: http://stackoverflow.com/questions/24037751/how-to-do-64bit-integer-arithmetic-in-node-js – Alex Klibisz Jun 13 '16 at 21:39
  • @Alex Klibisz - I cannot use Node.js. – Rewind Jun 13 '16 at 21:40
  • 1
    @Rewind: JavaScript's Number type only allows up to approximately 53 bits of precision. http://stackoverflow.com/questions/9643626/javascript-cant-handle-64-bit-integers-can-it. You'll have to find a "BigInteger" library to do the work that JavaScript can't do natively. – Cᴏʀʏ Jun 13 '16 at 21:41
  • @Rewind As the other question and Cory indicates, JS only stores 53 bits of precision. I'd suggest looking for a high-precision math library for JS that allows larger numbers. – Mike Cluck Jun 13 '16 at 21:42
  • Any suggestions? I am having trouble finding a good one. – Rewind Jun 13 '16 at 21:43
  • @Rewind Here's [the first result I found](http://mathjs.org/docs/datatypes/bignumbers.html) when searching for "js high precision numbers". – Mike Cluck Jun 13 '16 at 21:47
  • @Rewind: Peter Olson's library comes up fairly often: https://github.com/peterolson/BigInteger.js – Cᴏʀʏ Jun 13 '16 at 21:48

0 Answers0