Last active
December 26, 2022 18:04
-
-
Save Akinava/75695b28aa213fa0bf6d6a16f450a952 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# example hex file | |
""" | |
:100000000C9440000C944A000C944A000C944A0052 | |
:100010000C944A000C944A000C944A000C944A0038 | |
:100020000C944A000C944A000C944A000C944A0028 | |
:100030000C944A000C944A000C944A000C944A0018 | |
:100040000C944A000C944A000C944A000C944A0008 | |
:100050000C944A000C944A000C944A000C944A00F8 | |
:100060000C944A000C944A00010203040506070898 | |
:100070000000000000000000000000000000000080 | |
:1000800011241FBECFEFD8E0DEBFCDBF0E944F00CE | |
:100090000C9454000C940000559A5D9AFFCFE8E64A | |
:0C00A000F0E0E4910E944C00F894FFCFC7 | |
:00000001FF | |
""" | |
""" | |
first line :100000000C9440000C944A000C944A000C944A0052 | |
where: | |
:10 len | |
0000 address | |
00 data type | |
0C9440000C944A000C944A000C944A00 machine code's | |
52 controll summ | |
""" | |
def get_controll_summ(s): | |
s = s.replace(':', '') | |
sum = 0 | |
for x in range(int(len(s)/2)-1): | |
sum += int(s[x*2:x*2+2], 16) | |
sum = -(sum % 256) | |
return '%02X' % (sum & 0xFF), s[-2:] | |
>>> get_controll_summ(':100000000C9440000C944A000C944A000C944A0052') | |
<<< ('52', '52') # calculated and reference controll summ are matched!!! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment