xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

js & bitwise-operators

js & bitwise-operators

不用加减乘除运算符, 求整数的7倍


"use strict";

/**
 *
 * @author xgqfrms
 * @license MIT
 * @copyright xgqfrms
 * @created 2019-08-15
 *
 * @description bitwise-operators
 * @description 不用加减乘除运算符, 求整数的7倍
 * @description 7 times, without multiplication
 * @augments
 * @example
 * @link https://www.cnblogs.com/xgqfrms/p/11355923.html
 *
 */

let log = console.log;

// 7 times, without multiplication
const autoSeventTimes = (num = 0, times = 7) => {
    num = Math.abs(num);
    let x = Math.floor(times / 2);
    return (num << x) - num;
};

let xyz = autoSeventTimes(3);
// 21

console.log(`xyz =`, xyz);




©xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


posted @ 2020-06-02 23:13  xgqfrms  阅读(231)  评论(1编辑  收藏  举报