[next][previous][up][top][index]
search for:

transmitting an integer

The integer 0 is transmitted as a single zero byte. Otherwise, the sign of the integer is put into bit 6 of the first byte, and the bits of the absolute value of the integer are packed as follows: 6 bits into the first byte, 7 bits into 1, 2, or 3 more bytes, and 8 bits into each of the succeeding bytes. If 8 bit bytes are needed, then the number of them is sent as a positive integer after the first four bytes are sent. See also transmitting a positive integer. In the following illustration, S denotes the sign bit, and x's denote the bits of the integer.

     
          00000000     or
     
          0Sxxxxxx     or
     
          1Sxxxxxx 0xxxxxxx  or
     
          1Sxxxxxx 1xxxxxxx 0xxxxxxx  or
     
          1Sxxxxxx 1xxxxxxx 1xxxxxxx 0xxxxxxx   or
     
          1Sxxxxxx 1xxxxxxx 1xxxxxxx 1xxxxxxx   (first 27 bits)
          1xxxxxxx 0xxxxxxx                     (number of succeeding bytes)
          xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx   (succeeding bytes)
          xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx   (succeeding bytes)
          ...
          xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx   (succeeding bytes)
          xxxxxxxx xxxxxxxx                     (succeeding bytes)

i1 : binary = s -> concatenate between (" ",
               apply(s,x -> apply(8, i-> toString ((x >> 7-i) % 2))));

i2 : << binary ascii gg 63 << endl;
00111111

i3 : << binary ascii gg 64 << endl;
10000000 01000000

i4 : << binary ascii gg 127 << endl;
10000000 01111111

i5 : << binary ascii gg 128 << endl;
10000001 00000000

i6 : << binary ascii gg 2^10 << endl;
10001000 00000000

i7 : << binary ascii gg 2^20 << endl;
10000000 11000000 10000000 00000000

i8 : << binary ascii gg (-2^20) << endl;
11000000 11000000 10000000 00000000

i9 : << binary ascii gg 2^30 << endl;
10000010 10000000 10000000 10000000 00000001 00000000

i10 : << binary ascii gg 2^40 << endl;
10001000 10000000 10000000 10000000 00000010 00000000 00000000

i11 : << binary ascii gg 2^50 << endl;
10100000 10000000 10000000 10000000 00000011 00000000 00000000 00000000


[next][previous][up][top][index]
search for: