java - Int to byte array - byte shifting -
i'm trying convert int (max. 65535) 2 bytes array. in c used uint16, java doesn't know unsigned values.
to convert bytes array tried use this:
byte[] data = { (byte) ((num >> 8) & 0xff), (byte) (num & 0xff) };
but get: [63, -49] instead of: [63, 207], if use 16335 value. there way in java?
i need unsigned byte in byte array send using outputstream
you can use java's nio's bytebuffer purpose:
byte[] bytes = bytebuffer.allocate(4).putint(1695609641).array(); (byte b : bytes) { system.out.println(byte.tounsignedint(b)); }
hope work ;)
Comments
Post a Comment