{"id":7150,"date":"2021-04-26T22:11:08","date_gmt":"2021-04-26T16:41:08","guid":{"rendered":"https:\/\/nuclearrambo.com\/wordpress\/?p=7150"},"modified":"2024-10-03T15:08:54","modified_gmt":"2024-10-03T09:38:54","slug":"converting-a-binary-data-file-into-a-c-array-with-python","status":"publish","type":"post","link":"https:\/\/nuclearrambo.com\/wordpress\/converting-a-binary-data-file-into-a-c-array-with-python\/","title":{"rendered":"Converting a binary data file into a C array with a python script"},"content":{"rendered":"\n<p>Those working on embedded C\/C++ would know the importance of converting a binary file into a C array. I deal with raw images and ram dumps on daily basis. For example, I may be required to upload a raw image into the RAM connected to the processor for testing the rest of the code. At times, these raw images are simply some graphical elements of the user interface. My previous work flow was quite inefficient. Create an element in GIMP, export it as raw image.<a href=\"https:\/\/mh-nexus.de\/en\/hxd\/\" target=\"_blank\" rel=\"noopener\"> HxD<\/a> hex editor helps me convert the raw binary file into a compile-able C-array. A quick tool specifically made for this purpose would have been the perfect solution for me.<\/p>\n\n\n\n<p>I am a person who likes to remedy the situation. In this case, a quickly written Python script that generates C array from a binary file that can be compiled in any C compiler.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Read the binary data<\/h2>\n\n\n\n<p>We can quickly read the binary file with&nbsp;<em><a href=\"https:\/\/numpy.org\/\" target=\"_blank\" rel=\"noopener\">numpy<\/a>.&nbsp;<\/em>The&nbsp;<span style=\"font-family: 'courier new', courier;\">fromfile()<\/span> function makes our life simpler and that&#8217;s exactly what I will make use of.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">def read_file(file_name):\n    data = np.fromfile(file_name, dtype='uint8')\n    data = bytearray(data)\n    return data<\/pre>\n\n\n\n<p>To make the code re-usable, I prefer using functions. Who knows how large this code might grow in future. It&#8217;s always better to start with modular code. The read_file() function quickly reads the binary file. I am interpreting the file as a bunch of 8 bit data set. You could interpret it as an&nbsp;<em>int32, float or even double.&nbsp;<\/em>A file is always a bunch of bytes. Its upon us on how it should be interpreted. Finally, I am interpreting the data as a python <em><a href=\"https:\/\/docs.python.org\/3\/c-api\/bytearray.html\">bytearray<\/a>&nbsp;<\/em>and return the same.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Writing the data as ascii<\/h2>\n\n\n\n<p>A C source file is ascii text. We now need to convert our&nbsp;<em>bytearray&nbsp;<\/em>into ascii text. For this, I would be writing another function to do all this. After all, we would also need to format our ascii text. Packing all these tasks into a function would simply look cleaner. Okay, enough talking, lets get to work.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">def write_c_array(file_name, data):\n    c_file = open(file_name + \".c\", \"w\")\n    array_content = \"{{{}}}\".format(\", \".join(bytes_to_c_arr(data)))\n    c_file.write(array_content)<\/pre>\n\n\n\n<p>Our&nbsp;<em>write_c_array()&nbsp;<\/em>function takes two arguments; the file name and the data. Inside the function, we first create writable file with the file name passed in the argument. The&nbsp;<em>bytes_to_c_array()&nbsp;<\/em>function takes bytearray and returns ascii text that&#8217;s representative of the corresponding byte. The usual form is &#8220;0xhh&#8221; where h can be any value in range of 0 to F.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">def bytes_to_c_arr(data):\n    return [format(b, '#04x') for b in data]\n<\/pre>\n\n\n\n<p>Finally, we do two things. One is to add a comma and a whitespace after each hex string. Secondly, we encapsulate the whole strong between curly braces. Since, you already know that in C we can define an array with&nbsp;<em>unsigned char x[3] = {0x9, 0x4, 0x1};&nbsp;<\/em>Similarly, we need to add those curly braces to comply with the C syntax rules.<\/p>\n\n\n\n<p>Beware, if your file is large, you will end up with a multi-mega-byte C file that requires a better text editor such as notepad++. On linux you should open this with something like Vim. Gedit would simply struggle to open large files.<\/p>\n\n\n\n<center><p><script type=\"text\/javascript\">\n\tatOptions = {\n\t\t'key' : 'a488f095e80c8a74746e5fdca977eaea',\n\t\t'format' : 'iframe',\n\t\t'height' : 90,\n\t\t'width' : 728,\n\t\t'params' : {}\n\t};\n\tdocument.write('<scr' + 'ipt type=\"text\/javascript\" src=\"http' + (location.protocol === 'https:' ? 's' : '') + ':\/\/www.profitabledisplaynetwork.com\/a488f095e80c8a74746e5fdca977eaea\/invoke.js\"><\/scr' + 'ipt>');\n<\/script><\/p><\/center>\n\n\n\n<h2 class=\"wp-block-heading\">Calling our functions<\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">raw_data = read_file(\"raw_image.data\")\nwrite_c_array(\"c_file\", raw_data)<\/pre>\n\n\n\n<p>I called the two functions as shown above and ended up with a large C array.<\/p>\n\n\n\n<figure class=\"wp-block-image alignnone size-full wp-image-7151\"><img loading=\"lazy\" decoding=\"async\" width=\"974\" height=\"641\" src=\"https:\/\/nuclearrambo.com\/wordpress\/wp-content\/uploads\/2021\/04\/raw_image.png\" alt=\"raw data in python\" class=\"wp-image-7151\" srcset=\"https:\/\/nuclearrambo.com\/wordpress\/wp-content\/uploads\/2021\/04\/raw_image.png 974w, https:\/\/nuclearrambo.com\/wordpress\/wp-content\/uploads\/2021\/04\/raw_image-300x197.png 300w, https:\/\/nuclearrambo.com\/wordpress\/wp-content\/uploads\/2021\/04\/raw_image-768x505.png 768w\" sizes=\"auto, (max-width: 974px) 100vw, 974px\" \/><figcaption class=\"wp-element-caption\">Sample image<\/figcaption><\/figure>\n\n\n\n<p>I am attaching the raw version of this file that you use for yourself. Further in the article I shall tell you how to generate a raw binary for yourself.<\/p>\n\n\n\n<p><a href=\"https:\/\/nuclearrambo.com\/wordpress\/wp-content\/uploads\/2021\/04\/raw_image.zip\">raw_image<\/a><\/p>\n\n\n\n<p>Finally, I ended up with a .c file which contained all the hex values encapsulated in curly braces. Here&#8217;s a snippet.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">{0x70, 0x7d, 0x9f, 0xff, 0x71, 0x7e, 0xa0, 0xff,........\n<\/pre>\n\n\n\n<p>Now, for any C array to be usable, it needs to have some name. Let&#8217;s work on our python script to assign our array a name.<\/p>\n\n\n\n<p>Correspondingly, I modified my writing function to add some static content that creates a C array.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">static_content = \"unsigned char array[\" + str(len(data)) + \"] =\"<\/pre>\n\n\n\n<p>This should look like a C array definition. Furthermore, the&nbsp;<em>len(data)&nbsp;<\/em>also computes the size of the array. Although that&#8217;s not necessary in this particular style of definition. Finally, we are nearing the end of it. We are still not done yet. If we look at the file, it would be one long array that goes for miles beyond the screen. Stack Exchange to the rescue, I found a code snippet that does the formatting for us.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">final_content = re.sub(\"(.{66})\", \"\\\\1\\n\", final_content, 0, re.DOTALL)<\/pre>\n\n\n\n<p>This piece of code is responsible for adding new line after every 66 characters. You could have any number of characters. For example, 72, 36 also looks nicely aligned.<\/p>\n\n\n\n<figure class=\"wp-block-image alignnone\"><a href=\"https:\/\/nuclearrambo.com\/wordpress\/wp-content\/uploads\/2021\/04\/python_c_array_script.png\"><img loading=\"lazy\" decoding=\"async\" width=\"556\" height=\"553\" src=\"https:\/\/nuclearrambo.com\/wordpress\/wp-content\/uploads\/2021\/04\/python_c_array_script.png\" alt=\"Final auto generated C code with Python\" class=\"wp-image-7154\" srcset=\"https:\/\/nuclearrambo.com\/wordpress\/wp-content\/uploads\/2021\/04\/python_c_array_script.png 556w, https:\/\/nuclearrambo.com\/wordpress\/wp-content\/uploads\/2021\/04\/python_c_array_script-300x298.png 300w, https:\/\/nuclearrambo.com\/wordpress\/wp-content\/uploads\/2021\/04\/python_c_array_script-150x150.png 150w, https:\/\/nuclearrambo.com\/wordpress\/wp-content\/uploads\/2021\/04\/python_c_array_script-80x80.png 80w\" sizes=\"auto, (max-width: 556px) 100vw, 556px\" \/><\/a><figcaption class=\"wp-element-caption\">Final auto generated C code with Python<\/figcaption><\/figure>\n\n\n\n<center><p><script type=\"text\/javascript\">\n\tatOptions = {\n\t\t'key' : 'a488f095e80c8a74746e5fdca977eaea',\n\t\t'format' : 'iframe',\n\t\t'height' : 90,\n\t\t'width' : 728,\n\t\t'params' : {}\n\t};\n\tdocument.write('<scr' + 'ipt type=\"text\/javascript\" src=\"http' + (location.protocol === 'https:' ? 's' : '') + ':\/\/www.profitabledisplaynetwork.com\/a488f095e80c8a74746e5fdca977eaea\/invoke.js\"><\/scr' + 'ipt>');\n<\/script><\/p><\/center>\n\n\n\n<h2 class=\"wp-block-heading\">The final code<\/h2>\n\n\n\n<p>The python script isn&#8217;t too big and hopefully someone may find it useful.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import re\nimport numpy as np\n\n\ndef bytes_to_c_arr(data):\n    return [format(b, '#04x') for b in data]\n\n\ndef read_file(file_name):\n    data = np.fromfile(file_name, dtype='uint8')\n    data = bytearray(data)\n    return data\n\n\ndef write_c_array(file_name, data):\n    c_file = open(file_name + \".c\", \"w\")\n    static_content = \"unsigned char array[\" + str(len(data)) + \"] =\"\n    array_content = \"{{{}}}\".format(\", \".join(bytes_to_c_arr(data)))\n    final_content = static_content + array_content\n    final_content = re.sub(\"(.{72})\", \"\\\\1\\n\", final_content, 0, re.DOTALL)\n    c_file.write(final_content)\n\nraw_data = read_file(\"raw_image.data\")\nwrite_c_array(\"c_file\", raw_data)<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Those working on embedded C\/C++ would know the importance of converting a binary file into a C array. I deal with raw images and ram dumps on daily basis. For example, I may be&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":7155,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1562],"tags":[1775,1771,1774],"class_list":["post-7150","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-c","tag-embedded-systems","tag-python"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Converting a binary data file into a C array with a python script<\/title>\n<meta name=\"description\" content=\"I wrote a little python script that converts raw binary files into corresponding C array that can be compiled with a c compiler\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/nuclearrambo.com\/wordpress\/converting-a-binary-data-file-into-a-c-array-with-python\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Converting a binary data file into a C array with a python script\" \/>\n<meta property=\"og:description\" content=\"I wrote a little python script that converts raw binary files into corresponding C array that can be compiled with a c compiler\" \/>\n<meta property=\"og:url\" content=\"https:\/\/nuclearrambo.com\/wordpress\/converting-a-binary-data-file-into-a-c-array-with-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Nuclearrambo\" \/>\n<meta property=\"article:published_time\" content=\"2021-04-26T16:41:08+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-10-03T09:38:54+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/nuclearrambo.com\/wordpress\/wp-content\/uploads\/2021\/04\/photo_2021-04-26_22-10-07.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1280\" \/>\n\t<meta property=\"og:image:height\" content=\"960\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"nuclearrambo\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@darkusul\" \/>\n<meta name=\"twitter:site\" content=\"@darkusul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"nuclearrambo\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/nuclearrambo.com\/wordpress\/converting-a-binary-data-file-into-a-c-array-with-python\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/nuclearrambo.com\/wordpress\/converting-a-binary-data-file-into-a-c-array-with-python\/\"},\"author\":{\"name\":\"nuclearrambo\",\"@id\":\"https:\/\/nuclearrambo.com\/wordpress\/#\/schema\/person\/6093ae9d048d4789bd3d18c136577a0c\"},\"headline\":\"Converting a binary data file into a C array with a python script\",\"datePublished\":\"2021-04-26T16:41:08+00:00\",\"dateModified\":\"2024-10-03T09:38:54+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/nuclearrambo.com\/wordpress\/converting-a-binary-data-file-into-a-c-array-with-python\/\"},\"wordCount\":771,\"commentCount\":6,\"publisher\":{\"@id\":\"https:\/\/nuclearrambo.com\/wordpress\/#organization\"},\"keywords\":[\"c\",\"embedded systems\",\"python\"],\"articleSection\":[\"Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/nuclearrambo.com\/wordpress\/converting-a-binary-data-file-into-a-c-array-with-python\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/nuclearrambo.com\/wordpress\/converting-a-binary-data-file-into-a-c-array-with-python\/\",\"url\":\"https:\/\/nuclearrambo.com\/wordpress\/converting-a-binary-data-file-into-a-c-array-with-python\/\",\"name\":\"Converting a binary data file into a C array with a python script\",\"isPartOf\":{\"@id\":\"https:\/\/nuclearrambo.com\/wordpress\/#website\"},\"datePublished\":\"2021-04-26T16:41:08+00:00\",\"dateModified\":\"2024-10-03T09:38:54+00:00\",\"description\":\"I wrote a little python script that converts raw binary files into corresponding C array that can be compiled with a c compiler\",\"breadcrumb\":{\"@id\":\"https:\/\/nuclearrambo.com\/wordpress\/converting-a-binary-data-file-into-a-c-array-with-python\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/nuclearrambo.com\/wordpress\/converting-a-binary-data-file-into-a-c-array-with-python\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/nuclearrambo.com\/wordpress\/converting-a-binary-data-file-into-a-c-array-with-python\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/nuclearrambo.com\/wordpress\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Converting a binary data file into a C array with a python script\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/nuclearrambo.com\/wordpress\/#website\",\"url\":\"https:\/\/nuclearrambo.com\/wordpress\/\",\"name\":\"Nuclearrambo\",\"description\":\"Information is FREE! Progress is MUST! Awakening is inevitable!\",\"publisher\":{\"@id\":\"https:\/\/nuclearrambo.com\/wordpress\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/nuclearrambo.com\/wordpress\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/nuclearrambo.com\/wordpress\/#organization\",\"name\":\"Nuclearrambo\",\"url\":\"https:\/\/nuclearrambo.com\/wordpress\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/nuclearrambo.com\/wordpress\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/nuclearrambo.com\/wordpress\/wp-content\/uploads\/2021\/01\/logo-nuclearrambo.png\",\"contentUrl\":\"https:\/\/nuclearrambo.com\/wordpress\/wp-content\/uploads\/2021\/01\/logo-nuclearrambo.png\",\"width\":1489,\"height\":1152,\"caption\":\"Nuclearrambo\"},\"image\":{\"@id\":\"https:\/\/nuclearrambo.com\/wordpress\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/twitter.com\/darkusul\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/nuclearrambo.com\/wordpress\/#\/schema\/person\/6093ae9d048d4789bd3d18c136577a0c\",\"name\":\"nuclearrambo\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/nuclearrambo.com\/wordpress\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/9cc8a9d2d82dd7e65e77405f7b4ccaa34450e8a268f369ac893882cc5f13a797?s=96&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/9cc8a9d2d82dd7e65e77405f7b4ccaa34450e8a268f369ac893882cc5f13a797?s=96&r=g\",\"caption\":\"nuclearrambo\"},\"description\":\"Salil is an electronics enthusiast working on various electronics systems. In his free time he writes on the blog, talks over ham radio or builds circuits. He has Yaesu FT2900R VHF transceiver, FT450D HF transceiver, TYT UV8000E and Quansheng UVK6 Handheld transceivers.\",\"sameAs\":[\"http:\/\/nuclearrambo.com\/wordpress\"],\"url\":\"https:\/\/nuclearrambo.com\/wordpress\/author\/admin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Converting a binary data file into a C array with a python script","description":"I wrote a little python script that converts raw binary files into corresponding C array that can be compiled with a c compiler","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/nuclearrambo.com\/wordpress\/converting-a-binary-data-file-into-a-c-array-with-python\/","og_locale":"en_US","og_type":"article","og_title":"Converting a binary data file into a C array with a python script","og_description":"I wrote a little python script that converts raw binary files into corresponding C array that can be compiled with a c compiler","og_url":"https:\/\/nuclearrambo.com\/wordpress\/converting-a-binary-data-file-into-a-c-array-with-python\/","og_site_name":"Nuclearrambo","article_published_time":"2021-04-26T16:41:08+00:00","article_modified_time":"2024-10-03T09:38:54+00:00","og_image":[{"width":1280,"height":960,"url":"https:\/\/nuclearrambo.com\/wordpress\/wp-content\/uploads\/2021\/04\/photo_2021-04-26_22-10-07.jpg","type":"image\/jpeg"}],"author":"nuclearrambo","twitter_card":"summary_large_image","twitter_creator":"@darkusul","twitter_site":"@darkusul","twitter_misc":{"Written by":"nuclearrambo","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/nuclearrambo.com\/wordpress\/converting-a-binary-data-file-into-a-c-array-with-python\/#article","isPartOf":{"@id":"https:\/\/nuclearrambo.com\/wordpress\/converting-a-binary-data-file-into-a-c-array-with-python\/"},"author":{"name":"nuclearrambo","@id":"https:\/\/nuclearrambo.com\/wordpress\/#\/schema\/person\/6093ae9d048d4789bd3d18c136577a0c"},"headline":"Converting a binary data file into a C array with a python script","datePublished":"2021-04-26T16:41:08+00:00","dateModified":"2024-10-03T09:38:54+00:00","mainEntityOfPage":{"@id":"https:\/\/nuclearrambo.com\/wordpress\/converting-a-binary-data-file-into-a-c-array-with-python\/"},"wordCount":771,"commentCount":6,"publisher":{"@id":"https:\/\/nuclearrambo.com\/wordpress\/#organization"},"keywords":["c","embedded systems","python"],"articleSection":["Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/nuclearrambo.com\/wordpress\/converting-a-binary-data-file-into-a-c-array-with-python\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/nuclearrambo.com\/wordpress\/converting-a-binary-data-file-into-a-c-array-with-python\/","url":"https:\/\/nuclearrambo.com\/wordpress\/converting-a-binary-data-file-into-a-c-array-with-python\/","name":"Converting a binary data file into a C array with a python script","isPartOf":{"@id":"https:\/\/nuclearrambo.com\/wordpress\/#website"},"datePublished":"2021-04-26T16:41:08+00:00","dateModified":"2024-10-03T09:38:54+00:00","description":"I wrote a little python script that converts raw binary files into corresponding C array that can be compiled with a c compiler","breadcrumb":{"@id":"https:\/\/nuclearrambo.com\/wordpress\/converting-a-binary-data-file-into-a-c-array-with-python\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/nuclearrambo.com\/wordpress\/converting-a-binary-data-file-into-a-c-array-with-python\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/nuclearrambo.com\/wordpress\/converting-a-binary-data-file-into-a-c-array-with-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/nuclearrambo.com\/wordpress\/"},{"@type":"ListItem","position":2,"name":"Converting a binary data file into a C array with a python script"}]},{"@type":"WebSite","@id":"https:\/\/nuclearrambo.com\/wordpress\/#website","url":"https:\/\/nuclearrambo.com\/wordpress\/","name":"Nuclearrambo","description":"Information is FREE! Progress is MUST! Awakening is inevitable!","publisher":{"@id":"https:\/\/nuclearrambo.com\/wordpress\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/nuclearrambo.com\/wordpress\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/nuclearrambo.com\/wordpress\/#organization","name":"Nuclearrambo","url":"https:\/\/nuclearrambo.com\/wordpress\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/nuclearrambo.com\/wordpress\/#\/schema\/logo\/image\/","url":"https:\/\/nuclearrambo.com\/wordpress\/wp-content\/uploads\/2021\/01\/logo-nuclearrambo.png","contentUrl":"https:\/\/nuclearrambo.com\/wordpress\/wp-content\/uploads\/2021\/01\/logo-nuclearrambo.png","width":1489,"height":1152,"caption":"Nuclearrambo"},"image":{"@id":"https:\/\/nuclearrambo.com\/wordpress\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/twitter.com\/darkusul"]},{"@type":"Person","@id":"https:\/\/nuclearrambo.com\/wordpress\/#\/schema\/person\/6093ae9d048d4789bd3d18c136577a0c","name":"nuclearrambo","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/nuclearrambo.com\/wordpress\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/9cc8a9d2d82dd7e65e77405f7b4ccaa34450e8a268f369ac893882cc5f13a797?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/9cc8a9d2d82dd7e65e77405f7b4ccaa34450e8a268f369ac893882cc5f13a797?s=96&r=g","caption":"nuclearrambo"},"description":"Salil is an electronics enthusiast working on various electronics systems. In his free time he writes on the blog, talks over ham radio or builds circuits. He has Yaesu FT2900R VHF transceiver, FT450D HF transceiver, TYT UV8000E and Quansheng UVK6 Handheld transceivers.","sameAs":["http:\/\/nuclearrambo.com\/wordpress"],"url":"https:\/\/nuclearrambo.com\/wordpress\/author\/admin\/"}]}},"_links":{"self":[{"href":"https:\/\/nuclearrambo.com\/wordpress\/wp-json\/wp\/v2\/posts\/7150","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nuclearrambo.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nuclearrambo.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nuclearrambo.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nuclearrambo.com\/wordpress\/wp-json\/wp\/v2\/comments?post=7150"}],"version-history":[{"count":12,"href":"https:\/\/nuclearrambo.com\/wordpress\/wp-json\/wp\/v2\/posts\/7150\/revisions"}],"predecessor-version":[{"id":8413,"href":"https:\/\/nuclearrambo.com\/wordpress\/wp-json\/wp\/v2\/posts\/7150\/revisions\/8413"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nuclearrambo.com\/wordpress\/wp-json\/wp\/v2\/media\/7155"}],"wp:attachment":[{"href":"https:\/\/nuclearrambo.com\/wordpress\/wp-json\/wp\/v2\/media?parent=7150"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nuclearrambo.com\/wordpress\/wp-json\/wp\/v2\/categories?post=7150"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nuclearrambo.com\/wordpress\/wp-json\/wp\/v2\/tags?post=7150"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}