Skip to content

Instantly share code, notes, and snippets.

@bdkosher
Created September 18, 2013 13:53
Show Gist options
  • Save bdkosher/6609454 to your computer and use it in GitHub Desktop.
Save bdkosher/6609454 to your computer and use it in GitHub Desktop.
Represent an int as its array of bytes. (taken from http://java.dzone.com/articles/top-10-methods-java-arrays)
import java.nio.ByteBuffer;
int integer = 8;
byte[] bytes = ByteBuffer.allocate(4).putInt(integer).array();
for (byte t : bytes) {
System.out.format("0x%x ", t);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment