• Source
    1. #include <iostream>
    2. #include <bitset>
    3. using namespace std;
    4.  
    5. int main() {
    6. int x=-101;
    7. bitset<32> B(x);
    8. cout<<B<<endl;
    9. cout<<"16進位表達:"<<hex<<B.to_ulong()<<endl;
    10.  
    11. float f=-101;//
    12.  
    13. //reinterpret_cast 將一種型態的指標轉換為另一種型態的指標
    14. bitset<32> BF(*reinterpret_cast<unsigned long*>(&f));
    15. cout<<BF<<endl;//這就是儲存float f的方式
    16. cout<<"16進位表達:"<<hex<<BF.to_ulong()<<endl;
    17. return 0;
    18. }