我不知道计算机如何到达2 ^ 31 [英] I don't get how the computer arrives at 2^31

查看:84
本文介绍了我不知道计算机如何到达2 ^ 31的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题与以下几行代码有关:


#include< stdio.h>

#include< math.h>


int main(无效){


int a =(int)pow(2.0,32.0);

double b = pow(2.0,32.0);


printf(" a的值是:%u \ n,a);

printf(b的值是:%0.0f \ n,b);

printf(" int的值是:%d \ n",sizeof(int) ));

printf(" double的值是:%d \ n",sizeof(double));


返回0; < br $>
}


输出为:


$。/ pw

值a是:2147483648

b的值是:4294967296

int的值是:4

double的值是:8

''''(在我的机器上)的值是2147483648或2 ^ 31。无论如何

与这个案例中的1 int是32位有关吗?我需要提前付款。

Chad

The question is related to the following lines of code:

#include <stdio.h>
#include <math.h>

int main(void) {

int a = (int)pow(2.0 ,32.0);
double b = pow(2.0 , 32.0);

printf("The value of a is: %u\n",a);
printf("The value of b is: %0.0f\n",b);
printf("The value of int is: %d\n", sizeof(int));
printf("The value of double is: %d\n", sizeof(double));

return 0;
}

The output is:

$./pw
The value of a is: 2147483648
The value of b is: 4294967296
The value of int is: 4
The value of double is: 8
The value of ''a'' (on my machine) is 2147483648 or 2^31. Is this anyway
related to the fact that 1 int in this case is 32 bits? I

Thanks in advance.
Chad

推荐答案

./ pw

a的值是:2147483648

b的值是:4294967296

int的值是:4

double的值是:8

''''(在我的机器上)的值是2147483648或2 ^ 31。无论如何

与这个案例中的1 int是32位有关吗?我需要提前付款。

Chad

./pw
The value of a is: 2147483648
The value of b is: 4294967296
The value of int is: 4
The value of double is: 8
The value of ''a'' (on my machine) is 2147483648 or 2^31. Is this anyway
related to the fact that 1 int in this case is 32 bits? I

Thanks in advance.
Chad


Chad写道:
这个问题与以下几行代码有关:

#include< stdio.h>
#include< math.h>

int main(void){

int a =(int)pow(2.0,32.0);
double b = pow(2.0,32.0);

printf(" a的值是:%u \ n",a);
printf(" b的值是:%0.0f \ n",b);
printf(" int的值是:%d \ n",sizeof(int));
printf(" double的值是:%d \ n",sizeof(double)) ;

返回0;
}

输出结果为:

The question is related to the following lines of code:

#include <stdio.h>
#include <math.h>

int main(void) {

int a = (int)pow(2.0 ,32.0);
double b = pow(2.0 , 32.0);

printf("The value of a is: %u\n",a);
printf("The value of b is: %0.0f\n",b);
printf("The value of int is: %d\n", sizeof(int));
printf("The value of double is: %d\n", sizeof(double));

return 0;
}

The output is:


./ pw
a的值是:2147483648
b的值是:4294967296
int的值是:4
double的值是:8

''''(在我的机器上)的值是2147483648或2 ^ 31。无论如何这是否与在这种情况下1 int是32位的事实相关?我
./pw
The value of a is: 2147483648
The value of b is: 4294967296
The value of int is: 4
The value of double is: 8
The value of ''a'' (on my machine) is 2147483648 or 2^31. Is this anyway
related to the fact that 1 int in this case is 32 bits? I




尝试unsigned int。除非这是一个简单的测试代码,对于您正在处理的

数字的大小我会推荐很长时间。



Try unsigned int. Unless this is a simple test code, for the sizes the
numbers you are handling I''d recommend long long.


这篇关于我不知道计算机如何到达2 ^ 31的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆