码迷,mamicode.com
首页 > 编程语言 > 详细

用C语言写一个程序,得出当前系统的整形数字长(16位,32位,64位)等,不能使用sizeof()

时间:2015-04-10 21:40:02      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:

#include <iostream>
#include <cmath>
using namespace std;

int main()
{
int num = -1;
unsigned int s = num;              //当前位级表示即为最大无符号数
cout << (int)log2(s)+1 << endl; //第一种

int intSize = 0;
while(s != 0)
{
s = s >> 1;
intSize = intSize + 1;
}
cout << intSize << endl; //循环处理也行


int n = 1;        //直接用1,移位,,直到为0
int cn = 0;
while(n!=0)
{
n = (n << 1);
cn++;
}
cout << cn<< endl;
return 0;
}

用C语言写一个程序,得出当前系统的整形数字长(16位,32位,64位)等,不能使用sizeof()

标签:

原文地址:http://www.cnblogs.com/xlzhh/p/4415522.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!