Quickies

[categories] [index] [all (527)] [latest]

Python
  1. import struct
    import ctypes
    
    bytes = ctypes.create_string_buffer(8)
    struct.pack_into('i', bytes, 0, 10)
    struct.pack_into('f', bytes, 4, 0.5)
    
    f = open("file.dat", 'wb')
    f.write(bytes)
    f.close()
    

    result

    $ hexdump file.dat 
    0000000 0a 00 00 00 00 00 00 3f                        
    0000008