Skip to main content
gamedev.net
🔒 Locked

[java] byte data from a long & int

Started by 5MinuteGaming Apr 8, 2006 at 9:35 PM 1 replies 900+ views
Original Post
5MinuteGaming
5MinuteGaming
I am trying to write a Bitmap file creator to understand the format better. I am writing it in Java and kind of running into a road block as far as writing the data to file in the right byte sequence. Is there an easy way to convert basic types, int and long to a sequence of bytes?
shmoove
shmoove
You can use a DataOutputStream created with a ByteArrayOutputStream:
ByteOutputStream baos = new ByteOutputStream();DataOutputStream dos = new DataOutputStream(baos);

Use the writeXXX() method of the DataOutputStream:
dos.writeInt(someInt);dos.writeLong(someLong);

Then use the toByteArray() method of the ByteArrayOutputStream to get the array:
byte[] array = baos.toByteArray();


shmoove

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.