예제 #1
0
def test_compat_range():
    l1 = _range(3)
    assert isinstance(l1, list)
    assert hasattr(l1, 'pop')
    assert l1 == [0, 1, 2]

    it = _iter_range(3)
    assert not isinstance(it, list)
    assert hasattr(it, '__iter__')
    assert it != [0, 1, 2]
    assert list(it) == [0, 1, 2]
예제 #2
0
def test_compat_range():
    l1 = _range(3)
    assert isinstance(l1, list)
    assert hasattr(l1, 'pop')
    assert l1 == [0, 1, 2]

    it = _iter_range(3)
    assert not isinstance(it, list)
    assert hasattr(it, '__iter__')
    assert it != [0, 1, 2]
    assert list(it) == [0, 1, 2]
def bytes_to_bits():
    """
    :return: A 256 element list containing 8-bit binary digit strings. The
        list index value is equivalent to its bit string value.
    """
    lookup = []
    bits_per_byte = _range(7, -1, -1)
    for num in range(256):
        bits = 8 * [None]
        for i in bits_per_byte:
            bits[i] = "01"[num & 1]
            num >>= 1
        lookup.append("".join(bits))
    return lookup
def bytes_to_bits():
    """
    :return: A 256 element list containing 8-bit binary digit strings. The
        list index value is equivalent to its bit string value.
    """
    lookup = []
    bits_per_byte = _range(7, -1, -1)
    for num in range(256):
        bits = 8 * [None]
        for i in bits_per_byte:
            bits[i] = '01'[num & 1]
            num >>= 1
        lookup.append(''.join(bits))
    return lookup