FED68. 二进制转换
描述
获取数字 num 二进制形式第 bit 位的值。注意:示例1
输入:
128, 8
输出:
1
HTML/CSS/JavaScript 解法, 执行用时: 870ms, 内存消耗: 77784KB, 提交时间: 2020-12-29
{"css":"","js":"function valueAtBit(num, bit) {\n var newN = num.toString(2)\n return Number(newN.slice(newN.length-bit,newN.length-bit+1))\n}","html":"","libs":[]}
HTML/CSS/JavaScript 解法, 执行用时: 871ms, 内存消耗: 77788KB, 提交时间: 2020-12-29
{"css":"","js":"function valueAtBit(num, bit) {\n var bt = num.toString(2);\n return bt[bt.length-bit];\n}","html":"","libs":[]}
HTML/CSS/JavaScript 解法, 执行用时: 871ms, 内存消耗: 77900KB, 提交时间: 2020-12-26
{"css":"","js":"function valueAtBit(num, bit) {\n let str = num.toString(2);\n return str.substr(-bit,1);\n}","html":"","libs":[]}
HTML/CSS/JavaScript 解法, 执行用时: 871ms, 内存消耗: 77900KB, 提交时间: 2020-12-05
{"css":"","js":"function valueAtBit(num, bit) {\n var newN=num.toString(2)\n return Number(newN.slice(newN.length-bit,newN.length-bit+1));\n}","html":"","libs":[]}
HTML/CSS/JavaScript 解法, 执行用时: 872ms, 内存消耗: 77900KB, 提交时间: 2021-02-03
{"css":"","js":"function valueAtBit(num, bit) {\n var bitStr = num.toString(2);\n var len = bitStr.length; \n return bitStr[len - bit];\n}","html":"","libs":[]}