Advertisement

C++ 缺少 std::bin?如何显示二进制?掌握高效的二进制转换方法。

阅读量:
复制代码
    #include <bitset>
    #include <iostream>
    using namespace std;
    int main() {
    unsigned int hex_value0=0xaa;
    cout<<bitset<8>(hex_value0)<<endl;
    /*
    如果没有放入 8*sizeof (typename),仅仅放入常数如8可能只能显示被截断的后端的八位的字符。
    除非确定需要多少位,否则可以用以下形式:
    (其中8代表每个字节多少位,sizeof 变量名 代表该变量的字节数,可以不加括号。)
    */
    /*
    8*sizeof (typename) is required,
    for a constant value like 8 may truncate the value to output the last 8 bits.
    Unless you make up your mind to do this, you can use the following form:
    (8 indicates 8 bits per byte,
    and sizeof variable_name without parenthesis den

全部评论 (0)

还没有任何评论哟~