Monday, December 30, 2013

Converting java object to binary ,hex,octal string representation

Under development
Convert binary string to byte array
public static byte[] serialize(Object obj) throws IOException {
        ByteArrayOutputStream b = new ByteArrayOutputStream();
        ObjectOutputStream o = new ObjectOutputStream(b);
        o.writeObject(obj);
        return b.toByteArray();
    }

    public static Object deserialize(byte[] bytes) throws IOException, ClassNotFoundException {
        ByteArrayInputStream b = new ByteArrayInputStream(bytes);
        ObjectInputStream o = new ObjectInputStream(b);
        return o.readObject();
    }


http://java2novice.com/java-fundamentals/integer/binary-value/
http://www.java-examples.com/integer-wrapper-class

No comments:

Post a Comment