Gain
Gain

Reputation: 3853

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.

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

Upvotes: 0

Views: 660

Answers (3)

Usman Saleem
Usman Saleem

Reputation: 1655

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.

Upvotes: 0

Sergei Tachenov
Sergei Tachenov

Reputation: 24869

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.

Upvotes: 1

thejh
thejh

Reputation: 45568

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)

Upvotes: 0

Related Questions