输出内存中存储的二进制表示形式

#include 
#include
void show_bytes(unsigned char *start,int len)
{
    std::bitset<8> aByte;
    for (int i =0;i)
    {
        aByte = start[i];
        for (int j=0;j<8;j++)
        {
            std::cout<<aByte[j];
        }
        std::cout<<std::endl;
    }
}
void main()
{
    int i = 2;
    show_bytes((unsigned char*)&i,sizeof(i));
    std::cout<<"double d=3.0"<<std::endl;
    double d=3.0;
    show_bytes((unsigned char*)&d,sizeof(d));
}

 

转载于:https://www.cnblogs.com/lwngreat/p/4921651.html

你可能感兴趣的:(输出内存中存储的二进制表示形式)