Convert short to byte[] in Java -


How do I change a short (2 bytes) for a byte array in Java? , Such as

  small x = 233; Byte [] rate = new byte [2]; ...  

Something like this should be, but not sure.

  ((0xFF & lt; 8 & amp; nbsp; & amp; x) & gt; & Gt; 0; Edit:  

In addition to this, you can use it:

  java.nio.ByteOrder.nativeOrder ();  

The following code is taken from the java.io.bits to know if the original bit order is big or small:

  • Byte (array / offset)
  • Byte array
  • bit
  • bit
  • int
  • Byte array to float
  • Long-byte array
  • double byte array

and vice versa.

  ret [0] = (byte) (x and 0xff); Rate [1] = (byte) ((x> 8) & amp; 0xff);  

Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -