How to use the bitstring.BitArray 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 / test_bits.py View on Github external
def testCreationFromProperty(self):
        s = BitArray()
        s.uie = 45
        self.assertEqual(s.uie, 45)
        s.sie = -45
        self.assertEqual(s.sie, -45)
github keith-gray-powereng / dnp-modbus-decoder / power_decoder / tests.py View on Github external
def test_AHgetFunctionCode(self):
        testWord = bitstring.BitArray("0x00FF000000000000")
        result = BitSlice.getFuncCode(testWord)
        assert result.uint == bitstring.BitArray("0xFF").uint ,  "slice is pulling the wrong bits ({}, {})".format(result.uint, bitstring.BitArray("0xFA").uint)   
github AndrewMohawk / RfCatHelpers / RFSimpleReplay.py View on Github external
outputCapture = rawCapture
if(results.outFile != ''):
	pickle.dump(outputCapture, open(results.outFile,"wb"))
print "Send Phase..."
#print rawCapture
emptykey = '\x00\x00\x00\x00\x00\x00\x00'
d.makePktFLEN(len(emptykey))
d.RFxmit(emptykey)
while True:
	try:
		freq = raw_input("Press  to resend or type the frequency you wish to send on now:")
		if(freq != ''):
			d.setFreq(int(freq))
			
		for i in range(0,len(rawCapture)):
			key_packed = bitstring.BitArray(hex=rawCapture[i]).tobytes()
			if(results.waitForKeypress == True):
				raw_input(" Press any key to send " + str(i+1) + " of " + str(len(rawCapture)))
			d.makePktFLEN(len(key_packed))
			d.RFxmit(key_packed)
			print "Sent " + str(i+1) + " of " + str(len(rawCapture))
	except KeyboardInterrupt:
		print "Bye!"
		d.setModeIDLE()
		sys.exit()
		break;
print "exiting."
d.setModeIDLE()
github paguso / if76720182 / code / wumanber.py View on Github external
def wu_manber(txt, pat, ab, r, C=None):
    n = len(txt)
    m = len(pat)
    C = C if C else char_mask(pat, ab)
    S = [BitArray(bin = m*"1")<
github laforest / Octavo / Octavo / Assembler / Operators.py View on Github external
def __init__ (self):
        Debug.__init__(self)
        self.operator_width = 4

        self.always_zero    = BitArray("0b0000")
        self.a_and_b        = BitArray("0b1000")
        self.a_and_not_b    = BitArray("0b0100")
        self.a              = BitArray("0b1100")
        self.not_a_and_b    = BitArray("0b0010")
        self.b              = BitArray("0b1010")
        self.a_xor_b        = BitArray("0b0110")
        self.a_or_b         = BitArray("0b1110")
        self.a_nor_b        = BitArray("0b0001")
        self.a_xnor_b       = BitArray("0b1001")
        self.not_b          = BitArray("0b0101")
        self.a_or_not_b     = BitArray("0b1101")
        self.not_a          = BitArray("0b0011")
        self.not_a_or_b     = BitArray("0b1011")
        self.a_nand_b       = BitArray("0b0111")
        self.always_one     = BitArray("0b1111")
github cdecker / lightning-integration / lnaddr.py View on Github external
def tagged_bytes(char, l):
    return tagged(char, bitstring.BitArray(l))
github kh4l1d / CL3-Codes / Booths / booths.py View on Github external
# Initialize
	totalLength = x + y + 1
	mA = BitArray(int = m, length = totalLength)
	A = mA << (y+1)
	S = BitArray(int = -m, length = totalLength)  << (y+1)
	P = BitArray(int = r, length = y)
	P.prepend(BitArray(int = 0, length = x))
	P = P << 1
	print "Initial values"
	print "A", A.bin
	print "S", S.bin
	print "P", P.bin
	print "Starting calculation"
	for i in range(1,y+1):
		if P[-2:] == '0b01':
			P = BitArray(int = P.int + A.int, length = totalLength)
			print "P +  A:", P.bin
		elif P[-2:] == '0b10':
			P = BitArray(int = P.int +S.int, length = totalLength)
			print "P +  S:", P.bin
		P = arith_shift_right(P, 1)
		print "P >> 1:", P.bin
	P = arith_shift_right(P, 1)
	print "P >> 1:", P.bin
	return P.int
github datahq / dataflows / dataflows / processors / sort_rows.py View on Github external
def __call__(self, row):
        context = row.copy()
        for key, value in row.items():
            # We need to stringify some types to make them properly comparable
            if key in self.key_list:
                # numbers
                # https://www.h-schmidt.net/FloatConverter/IEEE754.html
                if isinstance(value, (int, float, decimal.Decimal)):
                    bits = BitArray(float=value, length=64)
                    # invert the sign bit
                    bits.invert(0)
                    # invert negative numbers
                    if value < 0:
                        bits.invert(range(1, 64))
                    context[key] = bits.hex
        return self.key_spec.format(**context)
github steffann / pylisp / pylisp / packet / lisp / control / map_notify.py View on Github external
'''
        # Verify that properties make sense
        self.sanitize()

        # Start with the type
        bitstream = BitArray('uint:4=%d' % self.message_type)

        # Add the flags
        has_xtr_site_id = bool(self.xtr_id or self.site_id)
        bitstream += BitArray('bool=%d' % has_xtr_site_id)

        # Add reserved bits
        bitstream += self._reserved1

        # Add record count
        bitstream += BitArray('uint:8=%d' % len(self.records))

        # Add the nonce
        bitstream += BitArray(bytes=self.nonce)

        # Add the key-id and authentication data
        bitstream += BitArray('uint:16=%d, uint:16=%d, hex=%s'
                              % (self.key_id,
                                 len(self.authentication_data),
                                 self.authentication_data.encode('hex')))

        # Add the map-reply records
        for record in self.records:
            bitstream += record.to_bitstream()

        # Add xTR-ID and site-ID if we said we would
        if has_xtr_site_id:
github n0mjs710 / DMRlink / Retired / ambe_audio.py View on Github external
def readAmbeFrameFromUDP( self, _sock ):
        _ambeAll = BitArray()               # Start with an empty array
        for i in range(0, 3):
            _ambe = self.readSock(_sock,7)  # Read AMBE from the socket
            if _ambe:
                _ambe1 = BitArray('0x'+h(_ambe[0:49]))
                _ambeAll += _ambe1[0:50]    # Append the 49 bits to the string
            else:
                break
        return _ambeAll.tobytes()           # Return the 49 * 3 as an array of bytes