gpt4 book ai didi

c++ - 大输入(64 位)在计算 C++ 中的 64 位整数中的位数时给出意想不到的结果

转载 作者:搜寻专家 更新时间:2023-10-31 00:11:55 24 4
gpt4 key购买 nike

<分区>

我正在尝试计算 64 位整数中的位数,但它显示出一些意外情况。这是代码。计数位不是主要部分,但一些意外的输出是....请查看输入和输出!!!!

#include<iostream>
#include<math.h>
#include<stdint.h>
#include<cstdio>
using namespace std;

int64_t t,n,ans;
int main(){
cin>>t;
while(t--){
int64_t ans=0;
cin>>n;
/*
while(n>0LL){
n>>=1LL;
ans++;
}//*/
ans=floor(log2(n));
//ans=floor(log2l(n));
cout<<ans<<"\n";

}
return 0;
}

输入输出是这样的

10
18446744073709551615

63(18446744073709551615 中的位数)应该只打印一次,控制台应该等到我输入另一个数字并计算其他数字中的位数。但它没有发生。输出是这样的。 ...

63
63
63
63
63
63
63
63
63
63

请帮我解决这个问题。

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com