node.js - Node.js 按位 OR 停止为大数字工作
问题描述
我正在尝试将 0 到 15 的 16 s 数组“压缩”number
为单个number
.
由于数组的每个元素最多为 15,我可以只用 4 位来表示它,所以我希望有 4 位 * 16 = 64 位适合number
.
为了做这个“压缩”,我使用了休闲功能:
function compressArray(array) {
return array.reduce(
(pre, curr, index) => {
return (pre | (curr * Math.pow(2, index * 4)));
},
0
);
}
但是在索引 8 之后,它会继续给我相同的输出而不计算正确的|
.
我在这里想念什么?
解决方案
推荐阅读
- python-3.x - Keras Model hdf5 无法转换 Tflite
- python - Python 和 selenium:如何多次更改 Firefox 的配置文件
- python - 如何迭代查询集并附加到字符串
- reactjs - 为什么我的 React 组件进入无限循环?
- python - 使用字典查找列表列表的最大值和最小值
- django - 在heroku中部署django应用程序后TemplateDoesNotFound错误
- flutter - 当抖动中不存在图像时处理图像错误
- python - Python Web Scraping 没有得到所有的 HTML
- python - Simpleaudio wav 文件只播放一次
- mysql - 了解具有 REPEATABLE_READ 和 READ_COMMITED 隔离级别的 InnoDB X-Lock