0

I was trying to extract last 32 bits from a Hex number in Javascript.

var hex = 0x6C469F301DBBC30;
var last32bit = (hex & 0xFFFFFFFF).toString(16);
log(last32bit); //gives 1dbbc40

The result is 1DBBC40. Shouldn't this supposed to be 1DBBC30 ? Also how do I preserve the 0 before 1DBBC40?

Terry
  • 989
  • 8
  • 29
Samik Sengupta
  • 1,944
  • 9
  • 31
  • 51

1 Answers1

3

The ECMA standard says:

The Number type has exactly 18437736874454810627 (that is, 264−253+3) values

Your number is too large to be represented exactly by a Number. You should look for a big number library if you wish to accurately represent large numbers. Perhaps one of these libraries would meet your needs.

Community
  • 1
  • 1
Dark Falcon
  • 43,592
  • 5
  • 83
  • 98