rest25/library/binascii.rst => rest262/library/binascii.rst
11   module: uu
12   module: base64
13   module: binhex
14
15The :mod:`binascii` module contains a number of methods to convert between
16binary and various ASCII-encoded binary representations. Normally, you will not
17use these functions directly but use wrapper modules like :mod:`uu`,
18:mod:`base64`, or :mod:`binhex` instead. The :mod:`binascii` module contains
n19-low-level functions written in C for greater speed that are used by the higher-
n19+low-level functions written in C for greater speed that are used by the
20-level modules.
20+higher-level modules.
21
22The :mod:`binascii` module defines the following functions:
23
24
25.. function:: a2b_uu(string)
26
27   Convert a single line of uuencoded data back to binary and return the binary
28   data. Lines normally contain 45 (binary) bytes, except for the last line. Line
108   Compute CRC-32, the 32-bit checksum of data, starting with an initial crc.  This
109   is consistent with the ZIP file checksum.  Since the algorithm is designed for
110   use as a checksum algorithm, it is not suitable for use as a general hash
111   algorithm.  Use as follows::
112
113      print binascii.crc32("hello world")
114      # Or, in two pieces:
115      crc = binascii.crc32("hello")
t116-      crc = binascii.crc32(" world", crc)
t116+      crc = binascii.crc32(" world", crc) & 0xffffffff
117-      print crc
117+      print 'crc32 = 0x%08x' % crc
118+ 
119+.. note::
120+   To generate the same numeric value across all Python versions and
121+   platforms use crc32(data) & 0xffffffff.  If you are only using
122+   the checksum in packed binary format this is not necessary as the
123+   return value is the correct 32bit binary representation
124+   regardless of sign.
125+ 
126+.. versionchanged:: 2.6
127+   The return value is in the range [-2**31, 2**31-1]
128+   regardless of platform.  In the past the value would be signed on
129+   some platforms and unsigned on others.  Use & 0xffffffff on the
130+   value if you want it to match 3.0 behavior.
131+ 
132+.. versionchanged:: 3.0
133+   The return value is unsigned and in the range [0, 2**32-1]
134+   regardless of platform.
118
119
120.. function:: b2a_hex(data)
121              hexlify(data)
122
123   Return the hexadecimal representation of the binary *data*.  Every byte of
124   *data* is converted into the corresponding 2-digit hex representation.  The
125   resulting string is therefore twice as long as the length of *data*.
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op