Skip to content

Instantly share code, notes, and snippets.

@jagannath-sahoo
Last active July 18, 2019 11:13
Show Gist options
  • Save jagannath-sahoo/d277d53e41253b016e04d03d082e0aff to your computer and use it in GitHub Desktop.
Save jagannath-sahoo/d277d53e41253b016e04d03d082e0aff to your computer and use it in GitHub Desktop.
Parsing the Intel hex format
/******************************************************************************
Online C Compiler.
Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char hex_code[] = ":1088E00020600DE0C8F80090FFF7E6FD064604E0C2";
char hex_addr[5] = {0};
char hex_data[32] = {0};
memcpy(hex_addr,&hex_code[3],4);
memcpy(hex_data,&hex_code[9],2);
hex_addr[4] = '\0';
hex_data[3] = '\0';
uint32_t data = (int)strtol(hex_data, NULL, 16);
uint32_t addr = 0;
addr = (int)strtol(hex_addr, NULL, 16);
//addr |= (fxxx<<12);
//addr |= (xfxx<<8);
//addr |= (xxfx<<4);
//addr |= (xxxf<<0);
printf("%x\n",addr + 0x08000000);
printf("%x\n",data);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment