Java长到二进制 [英] Java long to binary
问题描述
我认为简单的事情并没有那么多.
something I thought was simple ends up not so much.
我需要将一个长整数转换为二进制.
I need to convert a long number to binary.
例如:
String b = Integer.toBinaryString(1028);
输出为10000000100
the output is 10000000100
但是当我使用Integer.toBinaryString(2199023255552);这没用.当然,对于该函数来说,这个数字太大了,我找不到能从long转换过来的数字.
but when I use Integer.toBinaryString(2199023255552); it does not work. Of course the number is too big for this function and I can't find one that does convert from long.
有什么建议吗?
谢谢.
推荐答案
Add an L
to indicate its a long<1> and use the Long class<2>:
Long.toBinaryString(2199023255552L);
< 1>除非另有说明,否则Java中的常量被视为 int
.
<1> Constants in java are considered int
s unless you specify otherwise.
< 2> Integer.toBinaryString()
接收一个int作为参数,长度不长.
<2> Integer.toBinaryString()
receives an int as parameter, not long.
这篇关于Java长到二进制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!