简体   繁体   English

如何将整数从十进制转换为二进制

[英]How can I convert an int number from decimal to binary

how to convert an int array of length 8 to an int array of length 32 each 4 indexes are the binary representation of an index of the first array is there such a method that do all overhead. 如何将长度为8的int数组转换为长度为32的int数组,每个4个索引都是第一个数组的索引的二进制表示?

Edit, PST: I updated the title. 编辑,PST:我更新了标题。 However, this doesn't quite reflect with the notion of "binary", it's just decomposing integers into bytes. 但是,这并不能完全反映“二进制”的概念,它只是将整数分解为字节。 Correct and/or add examples if this is not accurate. 如果不正确,请更正和/或添加示例。

ok programers the main thing that i want is >> How can I convert an int number from decimal to binary 好的程序员,我要的主要是>>如何将整数从十进制转换为二进制

You can use ByteBuffer from java.nio. 您可以从java.nio使用ByteBuffer。 While the NIO can be sometimes cumbersome to use, its ByteBuffers are very nice and easy to use. 尽管NIO有时使用起来很麻烦,但它的ByteBuffer非常好并且易​​于使用。 Also be careful with endianness, by default it is BigEndian, but you can change that. 还要注意字节序,默认情况下是BigEndian,但是您可以更改它。

EDIT 编辑

Disregard this, I misread the question. 不管这个,我误解了问题。 It says convert int array to another int array, not to a byte array. 它说将int数组转换为另一个int数组,而不是字节数组。 Sorry. 抱歉。

Probably using all or some of the following (there is no direct way to achieve it): 可能会使用以下全部或部分内容(没有直接方法可以实现):

Integer.toBinaryString to get binary representation of your integer at your index. Integer.toBinaryString在索引处获取整数的二进制表示形式。
Array.newInstance Array.newInstance
System.arrayCopy System.arrayCopy
simple for loop etc. 简单的循环等

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

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