为什么当我将22+位十进制数转换为十六进制时结果为10?

时间:2017-01-27 18:13:25

标签: javascript

所以我编写了一个从十进制转换为十六进制的代码,当我输入一个22位数或更多时,结果总是20,有人可以解释为什么会发生这种情况?这是代码,我去了在线网站转换这样的数字,它在那里工作,但为什么不与我?:

function convert(x) {
    x = parseFloat(x);
    var mod = 0;
    var sum = "";
    var FinalSum = "";
    var y;
    var str;
    var slpha;
    var beta;
    while (x !== 0) {
      mod = x % 16;
      if (mod == 10) {
        sum += "a";
      } else if (mod == 11) {
        sum += "b";
      } else if (mod == 12) {
        sum += "c";
      } else if (mod == 13) {
        sum += "d"
      } else if (mod == 14) {
        sum += "e";
      } else if (mod == 15) {
        sum += "f";
      } else {
        sum += mod;
      }
      x = parseInt(x / 16);
    } //while loop end.

    /* everything is right 
	   till now but you have to
	   deal with the reverse issue */
    str = sum;
    alpha = sum.length - 1;
    beta = alpha + 1;
    while (alpha !== -1) {

      FinalSum += str.slice(alpha, beta);
      beta--;
      alpha--;

    } //while loop end.		   

    console.log(FinalSum);
  }
convert(1212312313123123123456);

0 个答案:

没有答案