作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
<分区>
我正在尝试计算 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
请帮我解决这个问题。
我是一名优秀的程序员,十分优秀!