码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-10-29 21:26:37      阅读:113      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!