class Solution {
public:
string printBin(double num) {
string ans="0.";
while(num!=0){
num*=2;
if(num>=1){
ans+="1";
num-=1;
}
else{
ans+="0";
}
if(ans.size()>32){return "ERROR";}
}
return ans;
}
};
面试题 05.02. 二进制数转字符串
最新推荐文章于 2024-11-11 20:59:17 发布