简体   繁体   English

如何找到大数的二进制表示?

[英]How to find binary representation of large numbers?

I wanted to convert a number to binary so i used the classic algorithm to solve the problem but at some point i don't get the true value because i exceed the max value of int is there any other solution to find the binary representation of lager numbers, beside using long or long long ?我想将一个数字转换为二进制,所以我使用经典算法来解决问题,但在某些时候我没有得到真实值,因为我超过了int的最大值是否有任何其他解决方案可以找到 lager 的二进制表示数字,除了使用longlong long吗?

If your numbers are outside the range that your machine can natively represent then you will have to switch to arbitrary-precision math.如果您的数字超出了您的机器本机可以表示的范围,那么您将不得不切换到任意精度的数学。 Find the largest power of two smaller than your target number, subtract, find the next largest subtract again and so on until you have nothing left.找到比你的目标数小的二的最大幂,减去,再次找到下一个最大的减法,依此类推,直到你一无所有。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM