Read about serialization.
You could make yourself using e.g. htonl(3), or endian(3).
You could use XDR with RPCGEN, or ASN.1.
You could use libs11n (in C++). You could also consider protocol buffers, etc...
Unless you have a lot of data, or bandwidth, you may consider using textual serialization formats like JSON (there are somehow flexible, easier to debug, etc...) or binary counterparts like BSON. Notice that sending data on a network is much slower than your CPU, so the overhead of textual serialization is generally lost in the noise (even if you compress it).