zoukankan      html  css  js  c++  java
  • 巧用c语言的位运算代替部分求余%计算

    网上看到一个文章,里面讲述了四种高效c语言执行的方法,

    1、使用空间代替时间

    2、使用数学优化,而不是死计算,笨计算

    3、使用位运算

    4、使用嵌入汇编

    前三点比较容易掌握,第四点基本上需要有比较深厚的汇编基础。

    这里讲讲位运算,

    1、无符号数据中, 左移1位,等价于除以2,右移1位,等价于乘以2,,切记不可溢出。

    2、求余数,

    J = 456 % 32;  ——456 - (456 >> 5 << 5);
    k = 456 % 64;  ——456 - (456 >> 6 << 6);
    l = 456 % 128;  ——456 - (456 >> 7 << 7);
    m = 456 % 256;  ——456 - (456 >> 8 << 8);

    这个方法只能对应2的整数幂,其他求余则不行

  • 相关阅读:
    windows nginx
    stdClass 标准
    array_merge
    array_pop
    array_push
    array_unique
    GMT与UTC简介(转)
    curl-手册
    13.5. zipfile — Work with ZIP archives
    7. Input and Output
  • 原文地址:https://www.cnblogs.com/CodeWorkerLiMing/p/12271068.html
Copyright © 2011-2022 走看看