convert bitset to int in c++

后端 未结 1 570
孤街浪徒
孤街浪徒 2020-12-14 09:22

In c++. I initialize a bitset to -3 like:

std::bitset<32> mybit(-3);

Is there a grace way that convert mybit to -3

相关标签:
1条回答
  • 2020-12-14 09:33

    Use to_ulong to convert it to unsigned long, then an ordinary cast to convert it to int.

    int mybit_int;
    
    mybit_int = (int)(mybit.to_ulong());
    

    DEMO

    0 讨论(0)
提交回复
热议问题