• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps integers to bytes

XsCode

Lurker
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:
byte High = (byte) (myInt);
byte Low = (byte) ((myInt >> 8) & 0xFF);

but i get -50 and 03 ???

Can anyone explain where i'm going wrong?

TIA
 
byte[] bytes = ByteBuffer.allocate(capacity).putInt(myInt).array();
 
Back
Top Bottom