简体   繁体   English

cout 打印错误

[英]Printing error in cout

I have a variable which is divided into 3 and 5 bits, and i am able to populate to each section ie a and b.我有一个分为 3 位和 5 位的变量,我可以填充到每个部分,即 a 和 b。

unsigned char a:3,b:5;

How can i print the values of both the section individually.我如何单独打印这两个部分的值。 If not how can I print as a whole.如果不是,我怎么能整体打印。

 cout << a << b ;

Please help me out.请帮帮我。

union Value
{
    unsigned char char_value;
    struct BitValue
    {   
        unsigned char three_bit:3;
        unsigned char five_bit:5;
    } bit_value;
};

int main()  
{  
    Value tmp;
    tmp.char_value=207;
    cout<<(unsigned int)tmp.bit_value.three_bit<<" "<<(unsigned int)tmp.bit_value.five_bit<<" "<<(unsigned int)tmp.char_value<<endl;
    return 0;
}

Maybe this is answer.也许这就是答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM