开发者

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 ove开发者_开发技巧rhead.

Edit, PST: I updated the title. 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. While the NIO can be sometimes cumbersome to use, its ByteBuffers are very nice and easy to use. Also be careful with endianness, by default it is BigEndian, but you can change that.

EDIT

Disregard this, I misread the question. It says convert int array to another int array, not to a byte array. Sorry.


I'm not sure, but maybe this is what you're looking for?

http://download.oracle.com/javase/1.4.2/docs/api/java/lang/Integer.html#toBinaryString(int)


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.
Array.newInstance
System.arrayCopy
simple for loop etc.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜