@@ -252,20 +252,25 @@ Binary Data
252
252
-----------
253
253
254
254
It is perfectly possible to send binary data over a socket. The major problem is
255
- that not all machines use the same formats for binary data. For example, a
256
- Motorola chip will represent a 16 bit integer with the value 1 as the two hex
257
- bytes 00 01. Intel and DEC, however, are byte-reversed - that same 1 is 01 00.
255
+ that not all machines use the same formats for binary data. For example,
256
+ `network byte order <https://en.wikipedia.org/wiki/Endianness#Networking >`_
257
+ is big-endian, with the most significant byte first,
258
+ so a 16 bit integer with the value ``1 `` would be the two hex bytes ``00 01 ``.
259
+ However, most common processors (x86/AMD64, ARM, RISC-V), are little-endian,
260
+ with the least significant byte first - that same ``1 `` would be ``01 00 ``.
261
+
258
262
Socket libraries have calls for converting 16 and 32 bit integers - ``ntohl,
259
263
htonl, ntohs, htons `` where "n" means *network * and "h" means *host *, "s" means
260
264
*short * and "l" means *long *. Where network order is host order, these do
261
265
nothing, but where the machine is byte-reversed, these swap the bytes around
262
266
appropriately.
263
267
264
- In these days of 32 bit machines, the ascii representation of binary data is
268
+ In these days of 64- bit machines, the ASCII representation of binary data is
265
269
frequently smaller than the binary representation. That's because a surprising
266
- amount of the time, all those longs have the value 0, or maybe 1. The string "0"
267
- would be two bytes, while binary is four. Of course, this doesn't fit well with
268
- fixed-length messages. Decisions, decisions.
270
+ amount of the time, most integers have the value 0, or maybe 1.
271
+ The string ``"0" `` would be two bytes, while a full 64-bit integer would be 8.
272
+ Of course, this doesn't fit well with fixed-length messages.
273
+ Decisions, decisions.
269
274
270
275
271
276
Disconnecting
0 commit comments