Last active
February 18, 2020 15:00
-
-
Save Farbklex/d7078c834c91618f7814bfd6fbfe7e07 to your computer and use it in GitHub Desktop.
Convert an Int to an array or list of Byte with a fixed length (int to byteArray with padding). Useful when a protocol requires you to allocate multiple bytes for one value but you don't need all of them to represent it.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Convert size int to a list of bytes | |
val intValue: Int = 4 | |
val intAsBytes = ByteBuffer.allocate(4).putInt(size).array().toList() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment