# -*- coding: utf-8 -*- #from __future__ import unicode_literals def hex2int(s): return int(s, 16) def hex2str(s): # Get the hex digits, without the leading '0x' return '%04X' % (int(s, 16)) def hexreverse(s): # Get the hex digits, without the leading '0x' hex_str = hex2str(s) #byte char split hexbytes = bytearray.fromhex(hex_str) hexbytes.reverse() hexbytes = hex2str(''.join('{:02x}'.format(x) for x in hexbytes)) # Read back the number in base 16 (hex) reversed_ = int(''.join(hexbytes), 16) return hex(reversed_) def hexmifare2w34(s): #Например код газпромбанка B1B2B3B4 в сфинкс как W34 нужно записывать как B4B3B2B1 return hex2str(hexreverse(s).replace('L', '')) def hexmifare2w26(s): #Например код газпромбанка B1B2B3B4 в сфинкс как W26 расчитывается: B3 переводим в десятичное число - это число перед запятой, B2B1 переводим в десятичное - это число после запятой # Get the hex digits, without the leading '0x' hex_str = hex2str(s) #byte char split hexbytes = bytearray.fromhex(hex_str) intpart = hex2int( ''.join('{:02x}'.format(hexbytes[2])) ) floatpart = hex2int( ''.join('{:02x}'.format(hexbytes[1])) + ''.join('{:02x}'.format(hexbytes[0])) ) return '{:0>3},{:0>5}'.format(intpart, floatpart) if __name__ == '__main__': MIFARE = 'EEB85DFC' W34 = hexmifare2w34(MIFARE) W26 = hexmifare2w26(MIFARE) print MIFARE, W34, W26 MIFARE = 'EEB85DF3' W34 = hexmifare2w34(MIFARE) W26 = hexmifare2w26(MIFARE) print MIFARE, W34, W26
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question