首页 > 其他 > 详细

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

时间:2015-10-29 21:24:53      阅读:313      评论:0      收藏:0      [点我收藏+]
#include <bitset>
#include<iostream>
void show_bytes(unsigned char *start,int len)
{
    std::bitset<8> aByte;
    for (int i =0;i<len;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));
}

 

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

原文:http://www.cnblogs.com/lwngreat/p/4921651.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!