eerimoq / bincopy

Mangling of various file formats that conveys binary information (Motorola S-Record, Intel HEX, TI-TXT, Verilog VMEM, ELF and binary files).
MIT License
109 stars 38 forks source link

ihex crc check breaks when crc is 0 #1

Closed apage43 closed 9 years ago

apage43 commented 9 years ago

https://github.com/eerimoq/bincopy/blob/6093eacbfd8f53bbe7b4f349d0e06e1bd42e22e3/bincopy.py#L30

The line crc = (0x100 - crc) will give 0x100 instead of 0x00 for the two's complement of zero.

Try crc = (~crc + 1) & 0xff instead.

eerimoq commented 9 years ago

Thanks for the bug report. I corrected the code and added a unittest for ihex crc calculations.