How to use the bitstring.BitString function in bitstring

To help you get started, we’ve selected a few bitstring examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github scott-griffiths / bitstring / test_bitstring.py View on Github external
def testRfindEndbit(self):
        a = BitString('0x000fff')
        b = a.rfind('0b011', bytealigned=False, start=0, end=14)
        self.assertEqual(b, True)
        b = a.rfind('0b011', False, 0, 13)
        self.assertEqual(b, False)
github scott-griffiths / bitstring / test_bitstring.py View on Github external
def testRorFromFile(self):
        a = BitString(filename='test/test.m1v')
        l = a.len
        a.ror(1)
        self.assertTrue(a.startswith('0x800000'))
        self.assertEqual(a.len, l)
        self.assertTrue(a.endswith('0x000db'))
github scott-griffiths / bitstring / test_bitstring.py View on Github external
def testDeleteBitsWithPosition(self):
        s = BitString(bin='000111100000')
        s.delete(4, 4)
        self.assertEqual(s.bin, '0b00010000')
github scott-griffiths / bitstring / test_bitstring.py View on Github external
def testInsertNull(self):
        s = BitString(hex='0x123').insert(BitString(), 3)
        self.assertEqual(s.hex, '0x123')
github scott-griffiths / bitstring / test_bitstring.py View on Github external
def testStructTokens2(self):
        endianness = sys.byteorder
        sys.byteorder = 'little'
        self.assertEqual(pack('@b', 23), BitString('intle:8=23'))
        self.assertEqual(pack('@B', 23), BitString('uintle:8=23'))
        self.assertEqual(pack('@h', 23), BitString('intle:16=23'))
        self.assertEqual(pack('@H', 23), BitString('uintle:16=23'))
        self.assertEqual(pack('@l', 23), BitString('intle:32=23'))
        self.assertEqual(pack('@L', 23), BitString('uintle:32=23'))
        self.assertEqual(pack('@q', 23), BitString('intle:64=23'))
        self.assertEqual(pack('@Q', 23), BitString('uintle:64=23'))
        sys.byteorder = 'big'
        self.assertEqual(pack('@b', 23), BitString('intbe:8=23'))
        self.assertEqual(pack('@B', 23), BitString('uintbe:8=23'))
        self.assertEqual(pack('@h', 23), BitString('intbe:16=23'))
        self.assertEqual(pack('@H', 23), BitString('uintbe:16=23'))
        self.assertEqual(pack('@l', 23), BitString('intbe:32=23'))
        self.assertEqual(pack('@L', 23), BitString('uintbe:32=23'))
        self.assertEqual(pack('@q', 23), BitString('intbe:64=23'))
        self.assertEqual(pack('@Q', 23), BitString('uintbe:64=23'))
        sys.byteorder = endianness
github scott-griffiths / bitstring / test_bitstring.py View on Github external
def testSetInvalidBin(self):
        s = BitString()
        self.assertRaises(ValueError, s._setbin, '00102')
github scott-griffiths / bitstring / test_bitstring.py View on Github external
def testCreationFromHexWithOffset(self):
        s = BitString(hex='0xa0b1c2', offset = 4)
        #s.hex
        self.assertEqual((s.length, s.hex), (20, '0x0b1c2'))
github scott-griffiths / bitstring / test_bitstring.py View on Github external
def testFileBasedAnySetUnset(self):
        a = BitString(filename='test/test.m1v')
        self.assertTrue(a.anyset((31, 12)))
        a = BitString(filename='test/test.m1v')
        self.assertTrue(a.anyunset((0, 1, 2, 3, 4)))
github scott-griffiths / bitstring / test_bitstring.py View on Github external
def testSliceNegativeStep(self):
        a = BitString('0o 01 23 45 6')
        self.assertEqual(a[::-3], '0o6543210')
        self.assertFalse(a[1:3:-6])
        self.assertEqual(a[2:0:-6], '0o4523')
        self.assertEqual(a[2::-6], '0o452301')
        b = a[::-1]
        a.reverse()
        self.assertEqual(b, a)
        b = BitString('0x01020408') + '0b11'
        self.assertEqual(b[::-8], '0x08040201')
        self.assertEqual(b[::-4], '0x80402010')
        self.assertEqual(b[::-2], '0b11' + BitString('0x20108040'))
        self.assertEqual(b[::-33], b[:33])
        self.assertEqual(b[::-34], b)
        self.assertFalse(b[::-35])
        self.assertEqual(b[-1:-3:-8], '0x0402')
github SoftwareQuTech / SimulaQron / cqc / backend / entInfoHeader.py View on Github external
def _unpack(self, headerBytes):
        """
        Unpack packet data. For definitions see cLib/cqc.h
        """
        ent_info_Bitstring = bitstring.BitString(headerBytes)
        type = ent_info_Bitstring.read("uint:4")
        if type != self.type:
            raise ValueError("Not an OK of type measure-directly")

        ent_info = ent_info_Bitstring.unpack(self.package_format)

        self.mhp_seq = ent_info[1]
        self.DF = ent_info[2]
        self.meas_out = ent_info[3]
        self.basis = ent_info[4]
        self.ip_A = ent_info[6]
        self.ip_B = ent_info[7]
        self.port_A = ent_info[8]
        self.port_B = ent_info[9]
        self.t_create = ent_info[10]
        self.goodness = ent_info[11]