Hi,
since Java doesn't provide a default way to do this,
what's a fast way to convert an Integer into a Byte Array?
e.g. 0xAABBCCDD => {AA, BB, CC, DD}
![]() ![]() ![]() 1
|
|||
|
![]() ![]() ![]() |
Have a look at the ByteBuffer class.
Setting the byte order ensures that Or alternatively, you could do it manually:
The
|
||||||||||||||
|
![]() ![]() |
Using
Using
Using
|
||||
|
![]() ![]() |
You can use From Integers:
The returned array is of the size that is needed to represent the number, so it could be of size 1, to represent 1 for example. However, the size cannot be more than four bytes if an int is passed. From Strings:
However, you will need to watch out, if the first byte is higher |
||||||
|