Skip to content

Instantly share code, notes, and snippets.

@Akinava
Last active December 26, 2022 18:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Akinava/75695b28aa213fa0bf6d6a16f450a952 to your computer and use it in GitHub Desktop.
Save Akinava/75695b28aa213fa0bf6d6a16f450a952 to your computer and use it in GitHub Desktop.
# 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