Back to index

eyed3  0.6.18
Functions
binfuncs Namespace Reference

Functions

def bytes2bin
 Copyright (C) 2002-2005 Travis Shirk travi.nosp@m.s@po.nosp@m.box.c.nosp@m.om Copyright (C) 2001 Ryan Finne ryan@.nosp@m.finn.nosp@m.ie.or.nosp@m.g
def bin2bytes
def bin2dec
def bytes2dec
def dec2bin
def dec2bytes
def bin2synchsafe
def bytes2str

Function Documentation

def binfuncs.bin2bytes (   x)

Definition at line 51 of file binfuncs.py.

00051 
00052 def bin2bytes(x):
00053    bits = [];
00054    bits.extend(x);
00055    bits.reverse();
00056 
00057    i = 0;
00058    out = '';
00059    multi = 1;
00060    ttl = 0;
00061    for b in bits:
00062       i += 1;
00063       ttl += b * multi;
00064       multi *= 2;
00065       if i == 8:
00066          i = 0;
00067          out += chr(ttl);
00068          multi = 1;
00069          ttl = 0;
00070 
00071    if multi > 1:
00072       out += chr(ttl);
00073 
00074    out = list(out);
00075    out.reverse();
00076    out = ''.join(out);
00077    return out;
00078 
# Convert and array of "bits" (MSB first) to it's decimal value.

Here is the caller graph for this function:

def binfuncs.bin2dec (   x)

Definition at line 79 of file binfuncs.py.

00079 
00080 def bin2dec(x):
00081    bits = [];
00082    bits.extend(x);
00083    bits.reverse();
00084 
00085    multi = 1;
00086    value = long(0);
00087    for b in bits:
00088       value += b * multi;
00089       multi *= 2;
00090    return value;

Here is the caller graph for this function:

Definition at line 114 of file binfuncs.py.

00114 
00115 def bin2synchsafe(x):
00116    if len(x) > 32 or bin2dec(x) > 268435456:   # 2^28
00117       raise ValueError("Invalid value");
00118    elif len(x) < 8:
00119       return x;
00120 
00121    n = bin2dec(x);
00122    bites = "";
00123    bites += chr((n >> 21) & 0x7f);
00124    bites += chr((n >> 14) & 0x7f);
00125    bites += chr((n >>  7) & 0x7f);
00126    bites += chr((n >>  0) & 0x7f);
00127    bits = bytes2bin(bites);
00128    if len(bits) < 32:
00129       bits = ([0] * (32 - len(x))) + bits;
00130 
00131    return bits;

Here is the call graph for this function:

Here is the caller graph for this function:

def binfuncs.bytes2bin (   bytes,
  sz = 8 
)

Copyright (C) 2002-2005 Travis Shirk travi.nosp@m.s@po.nosp@m.box.c.nosp@m.om Copyright (C) 2001 Ryan Finne ryan@.nosp@m.finn.nosp@m.ie.or.nosp@m.g

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

Definition at line 25 of file binfuncs.py.

00025 
00026 def bytes2bin(bytes, sz = 8):
00027    if sz < 1 or sz > 8:
00028       raise ValueError("Invalid sz value: " + str(sz));
00029 
00030    retVal = [];
00031    for b in bytes:
00032       bits = [];
00033       b = ord(b);
00034       while b > 0:
00035          bits.append(b & 1);
00036          b >>= 1;
00037 
00038       if len(bits) < sz:
00039          bits.extend([0] * (sz - len(bits)));
00040       elif len(bits) > sz:
00041          bits = bits[:sz];
00042 
00043       # Big endian byte order.
00044       bits.reverse();
00045       retVal.extend(bits);
00046 
00047    if len(retVal) == 0:
00048       retVal = [0];
00049    return retVal;
00050 
# Convert am array of bits (MSB first) into a string of characters.

Here is the caller graph for this function:

def binfuncs.bytes2dec (   bytes,
  sz = 8 
)

Definition at line 91 of file binfuncs.py.

00091 
00092 def bytes2dec(bytes, sz = 8):
00093     return bin2dec(bytes2bin(bytes, sz));
00094 
00095 # Convert a decimal value to an array of bits (MSB first), optionally
# padding the overall size to p bits.

Here is the call graph for this function:

Here is the caller graph for this function:

def binfuncs.bytes2str (   bytes)

Definition at line 132 of file binfuncs.py.

00132 
00133 def bytes2str(bytes):
00134     s = ""
00135     for b in bytes:
00136         s += ("\\x%02x" % ord(b))
00137     return s
def binfuncs.dec2bin (   n,
  p = 0 
)

Definition at line 96 of file binfuncs.py.

00096 
00097 def dec2bin(n, p = 0):
00098    assert(n >= 0)
00099    retVal = [];
00100 
00101    while n > 0:
00102       retVal.append(n & 1);
00103       n >>= 1;
00104 
00105    if p > 0:
00106       retVal.extend([0] * (p - len(retVal)));
00107    retVal.reverse();
00108    return retVal;

Here is the caller graph for this function:

def binfuncs.dec2bytes (   n,
  p = 0 
)

Definition at line 109 of file binfuncs.py.

00109 
00110 def dec2bytes(n, p = 0):
00111     return bin2bytes(dec2bin(n, p));
00112 
00113 # Convert a list of bits (MSB first) to a synch safe list of bits (section 6.2
# of the ID3 2.4 spec).

Here is the call graph for this function:

Here is the caller graph for this function: