Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(4)  |  Call(3)  |  Derive(0)  |  Import(1)
Parses a big endian integer from a list of bytes
taking only the first 7 bits from each byte

Do not set bits and mask parameters.

mask: 0111 1111 (removes 8th bit)
shift: offset to reorder bytes as if the 8th didn't exist
the bytes are walked in reverse order, as it is in big endian

This is because ID3v2 uses 'sync safe integers'(more...)

        def parse_7bitint(bytes, bits=7, mask=(1 << 7) - 1):
    """ Parses a big endian integer from a list of bytes
    taking only the first 7 bits from each byte

    Do not set bits and mask parameters.

    mask: 0111 1111 (removes 8th bit)
    shift: offset to reorder bytes as if the 8th didn't exist
    the bytes are walked in reverse order, as it is in big endian

    This is because ID3v2 uses 'sync safe integers'
    which always have its mrb zeroed

    > The tag size is encoded with four bytes where the most
    significant bit (bit 7) is set to zero in every byte, making a total
    of 28 bits. The zeroed bits are ignored, so a 257 bytes long tag is
    represented as $00 00 02 01.
    """
    return sum(
        (bytes[-i - 1] & mask) << shift
        for i, shift in
        enumerate(range(0, len(bytes) * bits, bits))
    )
        


src/m/p/mp3hash-0.1/tests/unit/test_parse_7bitint.py   mp3hash(Download)
#-*- coding: utf-8 -*-
 
from hamcrest import is_, assert_that
 
from mp3hash import parse_7bitint
    def test_parses_numbers_in_the_right_order(self):
        read_byte_string = [0x08, 0x04, 0x02, 0x01]
 
        parse = parse_7bitint(read_byte_string)
 
    def test_zeroes_8th_bit(self):
        # 0x80 is 1000 0000 with only the 8th bit on
        read_byte_string = [0x80, 0x80, 0x80, 0x80]
 
        parse = parse_7bitint(read_byte_string)
    def test_parses_8th_bit_while_keeping_the_rest(self):
        # 0xFF (11111 1111) will become 0x7F (0111 1111)
        read_byte_string = [0xFF, 0xFF, 0xFF, 0xFF]
 
        parse = parse_7bitint(read_byte_string)