Implemented the rest of write_to_hex