This is a lot of duplicate code; maybe there is a way to extract the common code from `ihex_mem_copy` and `ihex_byte_copy`?