I want to  serialize number to byte array on  Android, send bytes by
UDP, and deserialize number from bytes on the  desctop jvm

It is work fine on  Emulator SDK 2.0. And it is does not work on
Emulator SDK 1.5 (and on HTC Hero)

I use the following functions for serialization. Does anybody know the
reason?



    public static byte[] intToByteArray(Integer value) {
        if (value == null) {
            return new byte[]{(byte) 0xFFFF, (byte) 0xFFFF, (byte)
0xFFFF, (byte) 0xFFFF};
        }
        return new byte[]{
                (byte) ((int) value >>> 24),
                (byte) ((int) value >>> 16),
                (byte) ((int) value >>> 8),
                (byte) (int) value};
    }

    public static Integer byteArrayToInt(byte[] b) {
        return (b[0] << 24)
                + ((b[1] & 0xFF) << 16)
                + ((b[2] & 0xFF) << 8)
                + (b[3] & 0xFF);
    }


    public static byte[] shortToByteArray(Short value) {
        if (value == null) {
            return new byte[]{(byte) 0xFFFF, (byte) 0xFFFF};
        }
        return new byte[]{(byte) ((value & 0xFF00) >> 8), (byte)
(value & 0x00FF)};
    }

    public static Short byteArrayToShort(byte[] b) {
        return (short) (((b[0] << 8)) | ((b[1] & 0xff)));
    }

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to