0

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

asked Dec 14, 2010 at 20:15
10
  • Why do you want to do that? Internally, everything is already binary. Commented 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 thejh Commented Dec 14, 2010 at 20:20
  • 1
    Can you please clarify your question and give some context? Your lack of punctuation especially is making this hard to read. Commented Dec 14, 2010 at 20:21
  • @Sami: Why do you want to do that? Also, internally, the radix is irrelevant. Commented Dec 14, 2010 at 20:22
  • 1
    Can you please add an example. Commented Dec 14, 2010 at 20:22

3 Answers 3

1

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.

answered Dec 14, 2010 at 20:24
Sign up to request clarification or add additional context in comments.

Comments

0

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)

answered Dec 14, 2010 at 20:23

Comments

0

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.

answered Dec 14, 2010 at 20:25

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.