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.
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
-
Why do you want to do that? Internally, everything is already binary.thejh– thejh2010年12月14日 20:18:23 +00:00Commented Dec 14, 2010 at 20:18
-
actualy the first array is an array of decimal int which is radix=10 i want each index of the first to be represented int 4 indexes in the second array in radix=2 which means bainary i hope it clear now thejhGain– Gain2010年12月14日 20:20:56 +00:00Commented Dec 14, 2010 at 20:20
-
1Can you please clarify your question and give some context? Your lack of punctuation especially is making this hard to read.DGH– DGH2010年12月14日 20:21:22 +00:00Commented Dec 14, 2010 at 20:21
-
@Sami: Why do you want to do that? Also, internally, the radix is irrelevant.thejh– thejh2010年12月14日 20:22:04 +00:00Commented Dec 14, 2010 at 20:22
-
1Can you please add an example.aioobe– aioobe2010年12月14日 20:22:15 +00:00Commented Dec 14, 2010 at 20:22
3 Answers 3
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.
Comments
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)
Comments
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.