integers to bytes

Discussion in 'Application Development' started by XsCode, Oct 14, 2010.

  1. XsCode

    XsCode Member
    5

    Jul 14, 2010
    7
    0
    5
    Hi all,

    I'm new to Java programming, coming from VB6 programming many years back.

    I'm trying to send a HCI command, but the params are sent as bytes and I can't seem to get the integer I want to send to form the correct bytes.

    my example integer is 974 which when using hcidump is sent as 00 78 82. I understand that 0x78 * 0x82 = 0x3CF ie 974, but I can't work out how to get the bytes from the integer.

    I've tried bit shifting with..

    Code (Text):
    1.  
    2. byte High = (byte) (myInt);
    3. byte Low = (byte) ((myInt >> 8) & 0xFF);
    4.  
    but i get -50 and 03 ???

    Can anyone explain where i'm going wrong?

    TIA
     

    Advertisement

  2. byte[] bytes = ByteBuffer.allocate(capacity).putInt(myInt).array();
     

Share This Page

Loading...