Example #1
0
    def write_variablenumber(self, value):
        assert value >= 2

        length = _misc.getbinlen(value) - 2 # the highest bit is 1
        self.write_bit(value & (1 << length))
        for i in xrange(length - 1, -1, -1):
            self.write_bit(1)
            self.write_bit(value & (1 << i))
        self.write_bit(0)
        return
Example #2
0
    def write_variablenumber(self, value):
        assert value >= 2

        length = _misc.getbinlen(value) - 2  # the highest bit is 1
        self.write_bit(value & (1 << length))
        for i in xrange(length - 1, -1, -1):
            self.write_bit(1)
            self.write_bit(value & (1 << i))
        self.write_bit(0)
        return
Example #3
0
def get_params(source_base, target_base):
    """takes 2 bases, calculate the bit-length they have to be encoded in,
    the common block length both can be encoded in,
    and the amount of symbols contained in that block, for each base"""
    source_width, target_width = [
        getbinlen(len(b) - 1) for b in [source_base, target_base]
    ]  # how many bits necessary to encode a base
    block_width = lcm(source_width, target_width)  # smallest block bit-length to store both

    source_length, target_length = [
        block_width / i for i in [source_width, target_width]
    ]  # how many chars to read to fill a block
    return block_width, source_width, source_length, target_width, target_length
Example #4
0
def get_params(source_base, target_base):
    """takes 2 bases, calculate the bit-length they have to be encoded in,
    the common block length both can be encoded in,
    and the amount of symbols contained in that block, for each base"""
    source_width, target_width = [
        getbinlen(len(b) - 1) for b in [source_base, target_base]
    ]  # how many bits necessary to encode a base
    block_width = lcm(source_width,
                      target_width)  # smallest block bit-length to store both

    source_length, target_length = [
        block_width / i for i in [source_width, target_width]
    ]  # how many chars to read to fill a block
    return block_width, source_width, source_length, target_width, target_length
Example #5
0
 def __updateindexbase(self, value):
     self.write_bitstring("111")
     self.write_fixednumber(0, 7)
     nb = getbinlen(value)
     self.write_fixednumber(value, nb - 3)
Example #6
0
 def __updateindexbase(self, value):
     self.write_bitstring("111")
     self.write_fixednumber(0, 7)
     nb = getbinlen(value)
     self.write_fixednumber(value, nb - 3)
Example #7
0
 nibbleswap, rol, ror, rorstr, setstr, zip_extend, lcm, slice_and_pad)

import struct

assert char_range("A", "Z") == "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

#gcd
#returns the greatest common divisor of both parameters
assert gcd(6, 8) == 2

#lcm
#returns the least common multiplier of both parameters
assert lcm(6, 9) == 18
assert lcm(6, 8) == 24

assert getbinlen(0) == 1
assert getbinlen(1) == 1
assert getbinlen(3) == 2

assert getvaluefrombinarystring("1000") == 8
assert getvaluefrombinarystring("001000") == 8

assert getpadbinstr(8, 8) == "00001000"

assert getunkbinstr(0, 0, 8) == "000000000"
assert getunkbinstr(1, 0, 8) == "000000001"
assert getunkbinstr(2, 1, 8) == "00000001x"
assert getunkbinstr(237, 3, 8) == "011101xxx"

assert gethexstr("\x00") == "00"
assert gethexstr("\x00\x01") == "00 01"
Example #8
0
                       slice_and_pad)

import struct

assert char_range("A", "Z") == "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

#gcd
#returns the greatest common divisor of both parameters
assert gcd(6, 8) == 2

#lcm
#returns the least common multiplier of both parameters
assert lcm(6, 9) == 18
assert lcm(6, 8) == 24

assert getbinlen(0) == 1
assert getbinlen(1) == 1
assert getbinlen(3) == 2

assert getvaluefrombinarystring("1000") == 8
assert getvaluefrombinarystring("001000") == 8

assert getpadbinstr(8, 8) == "00001000"

assert getunkbinstr(0, 0, 8) == "000000000"
assert getunkbinstr(1, 0, 8) == "000000001"
assert getunkbinstr(2, 1, 8) == "00000001x"
assert getunkbinstr(237, 3, 8) == "011101xxx"

assert gethexstr("\x00") == "00"
assert gethexstr("\x00\x01") == "00 01"