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

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);



Flag Counter

©xgqfrms 2012-2020

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


原文地址:https://www.cnblogs.com/xgqfrms/p/13034550.html