C++使用按位右移/按位左移运算符

1.按位右移运算符(>>)
将数据除以2^n(2的n次方)

2.按位左移运算符(<<)
将数据乘以2^n(2的n次方)

使用按位运算符计算数据

#include<iostream>

using namespace std;

int main()
{
    cout << "Enter a number:";
    int Input = 0;
    cin >> Input;

    int Half = Input >> 1;
    int Quarter = Input >> 2;
    int Double = Input << 1;
    int Quadruple = Input << 2;

    cout << "Half:" << Half << endl;
    cout << "Quarter:" << Quarter << endl;
    cout << "Double:" << Double << endl;
    cout << "Quadruple:" << Quadruple << endl;


    return 0;

}

效果图
C++使用按位右移/按位左移运算符

原文链接: https://www.cnblogs.com/ButterflyEffect/p/6370776.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    C++使用按位右移/按位左移运算符

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/248815

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月14日 上午3:13
下一篇 2023年2月14日 上午3:14

相关推荐