Java长到二进制 [英] Java long to binary

查看:47
本文介绍了Java长到二进制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为简单的事情并没有那么多.

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.

有什么建议吗?

谢谢.

推荐答案

添加 L 以表示其长的< 1>并使用

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 ints unless you specify otherwise.

< 2> Integer.toBinaryString()接收一个int作为参数,长度不长.

<2> Integer.toBinaryString() receives an int as parameter, not long.

这篇关于Java长到二进制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆