Write short to little-endian byte array - Android File Input Output

Android examples for File Input Output:Byte Array Convert

Description

Write short to little-endian byte array

Demo Code


//package com.book2s;

import java.io.IOException;

public class Main {
    /**/*from   w w w.ja v  a 2 s  . c om*/
     * Write short to little-endian byte array
     * @param value
     * @return
     * @throws IOException
     */
    private static byte[] writeShort(short value) throws IOException {
        byte[] b = new byte[2];

        b[0] = (byte) (value & 0x00FF);
        b[1] = (byte) ((value & 0xFF00) >> 8);

        return b;
    }
}

Related Tutorials