-
-
Save ivand58/7d0b3242e96c8320b7623ddf18077b39 to your computer and use it in GitHub Desktop.
Vim Script Intel HEX Checksum
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
function IHexChecksum() | |
let l:data = getline(".") | |
let l:dlen = strlen(data) | |
if (empty(matchstr(l:data, "^:\\(\\x\\x\\)\\{5,}$"))) | |
echoerr("Input is not a valid Intel HEX line!") | |
return | |
endif | |
let l:byte = 0 | |
for l:bytepos in range(1, l:dlen-4, 2) | |
let l:byte += str2nr(strpart(l:data, l:bytepos, 2), 16) | |
endfor | |
let l:byte = (256-(l:byte%256))%256 | |
call setline(".", strpart(l:data, 0, l:dlen-2).printf("%02x", l:byte)) | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment