Over a million developers have joined DZone.
Gold Partner

Convert an Int to a Byte Array

Convert an int into a byte array with this short code snippet.

· Java Zone

The Java Zone is brought to you in parnership with New Relic. Read about the 10 Surprisingly Interesting Ways to Earn a Living Using Java and rejuvenate your love for programming.


    public static byte[] intToByteArray(int value) {
        byte[] b = new byte[4];
        for (int i = 0; i >> offset) & 0xFF);
        }
        return b;
    }


The Java Zone is brought to you in parnership with New Relic. Read about the 10 Surprisingly Interesting Ways to Earn a Living Using Java and rejuvenate your love for programming.

Topics:
java

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}