Representing a number in a byte array (java programming)
        Posted  
        
            by Mark Roberts
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Mark Roberts
        
        
        
        Published on 2010-05-19T19:51:54Z
        Indexed on 
            2010/05/19
            20:00 UTC
        
        
        Read the original article
        Hit count: 159
        
I'm trying to represent the port number 9876 (or 0x2694 in hex) in a two byte array:
class foo {
     public static void main (String args[]) {
      byte[] sendData = new byte[1];
      sendData[0] = 0x26;
      sendData[1] = 0x94;
     }
}
But I get a warning about possible loss of precision:
foo.java:5: possible loss of precision
found   : int
required: byte
      sendData[1] = 0x94;
                    ^
1 error
How can I represent the number 9876 in a two byte array without losing precision?
© Stack Overflow or respective owner