1

I'm using a simple technique to convert binary numbers to hexadecimal.

parseInt('1011110000',2).toString(16) == '2f0'
parseInt('111110011111101111100111011011001',2).toString(16) == '1F3F7CED9'

With larger binary numbers, I'm encountering a problem:

parseInt('11000011010011001100110011001100110011001100110011001100',2).toString(16);

Returns c34cccccccccd0 instead of correct value c34cccccccccc.

Minus four bits solve the problem:

parseInt('1100001101001100110011001100110011001100110011001100',2).toString(16);

Returns c34cccccccccc.

Why does this happen? How can I avoid this problem and convert large binary numbers into hexadecimal numbers?

user229044
  • 232,980
  • 40
  • 330
  • 338
Ilya Manyahin
  • 238
  • 3
  • 12

0 Answers0