[Algorithm] Convert a number from decimal to binary

Posted answer1215

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[Algorithm] Convert a number from decimal to binary相关的知识,希望对你有一定的参考价值。

125, how to conver to binary number?

技术图片

 

function DecimalToDinary (n) {
  let temp = n;
  let list = [];

  if (temp <= 0) {
    return ‘0000‘;
  }

  while (temp > 0) {
    let rem = temp % 2;
    list.push(rem);
    temp = parseInt(temp / 2, 10);
  }

  return list.reverse().join(‘‘);
}

console.log(DecimalToDinary(125)) // 1111101

 

以上是关于[Algorithm] Convert a number from decimal to binary的主要内容,如果未能解决你的问题,请参考以下文章

108. Convert Sorted Array to Binary Search Tree

108. Convert Sorted Array to Binary Search Tree

自定义类型转化

LeetCode Algorithm 414. 第三大的数

Given an array where elements are sorted in ascending order, convert it to a height balanced BST.(示例

c#中 Double num1 = Convert.ToDouble(this.textBox1.Text.ToString())是啥意思,里面的()是啥意思