{"id":3886,"date":"2025-05-14T14:23:48","date_gmt":"2025-05-14T19:23:48","guid":{"rendered":"https:\/\/dumpflashedit.com\/?page_id=3886"},"modified":"2025-05-29T12:37:33","modified_gmt":"2025-05-29T17:37:33","slug":"convertidor-hexbin","status":"publish","type":"page","link":"https:\/\/dumpflashedit.com\/index.php\/convertidor-hexbin\/","title":{"rendered":"Convertidor hexbin"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-page\" data-elementor-id=\"3886\" class=\"elementor elementor-3886\">\n\t\t\t\t<div class=\"elementor-element elementor-element-6d7ed08 e-flex e-con-boxed e-con e-parent\" data-id=\"6d7ed08\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t\t\t<div class=\"elementor-element elementor-element-caaf273 elementor-widget elementor-widget-html\" data-id=\"caaf273\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<!DOCTYPE html>\r\n<html lang=\"es\">\r\n<head>\r\n  <meta charset=\"UTF-8\">\r\n  <title>Convertidor HEX \u21c4 BIN<\/title>\r\n<\/head>\r\n<body style=\"font-family: sans-serif; padding: 20px;\">\r\n  <h2>Convertidor HEX \u21c4 BIN<\/h2>\r\n  <input type=\"file\" id=\"fileInput\" \/>\r\n  <br><br>\r\n  <button id=\"convertBtn\" disabled>Sube tu archivo HEX\/BIN<\/button>\r\n\r\n  <script>\r\n    let fileData = null;\r\n    let fileName = '';\r\n\r\ndocument.getElementById('fileInput').addEventListener('change', async (event) => {\r\n  const file = event.target.files[0];\r\n  const convertBtn = document.getElementById('convertBtn');\r\n  if (!file) return;\r\n\r\n  fileName = file.name;\r\n  const reader = new FileReader();\r\n  reader.onload = () => {\r\n    fileData = reader.result;\r\n    convertBtn.disabled = false;\r\n  };\r\n\r\n  if (file.name.endsWith('.hex')) {\r\n    reader.readAsText(file);\r\n    convertBtn.textContent = 'Convertir a BIN';\r\n  } else if (file.name.endsWith('.bin')) {\r\n    reader.readAsArrayBuffer(file);\r\n    convertBtn.textContent = 'Convertir a HEX';\r\n  } else {\r\n    alert('Solo se permiten archivos .hex o .bin');\r\n    convertBtn.disabled = true;\r\n  }\r\n});\r\n\r\n\r\n    document.getElementById('convertBtn').addEventListener('click', () => {\r\n      if (fileName.endsWith('.hex')) {\r\n        const binData = hexToBin(fileData);\r\n        downloadFile(new Uint8Array(binData), fileName.replace('.hex', '_converted.bin'), 'application\/octet-stream');\r\n      } else if (fileName.endsWith('.bin')) {\r\n        const hexText = binToHex(new Uint8Array(fileData));\r\n        downloadFile(hexText, fileName.replace('.bin', '_converted.hex'), 'text\/plain');\r\n      }\r\n    });\r\n\r\nfunction hexToBin(hexText) {\r\n  const lines = hexText.trim().split(\/\\r?\\n\/);\r\n  const memory = new Map();\r\n  let extAddr = 0;\r\n\r\n  for (let line of lines) {\r\n    if (!line.startsWith(':')) continue;\r\n\r\n    const byteCount = parseInt(line.slice(1, 3), 16);\r\n    const address = parseInt(line.slice(3, 7), 16);\r\n    const recordType = parseInt(line.slice(7, 9), 16);\r\n\r\n    if (recordType === 4) {\r\n      extAddr = parseInt(line.slice(9, 13), 16) << 16;\r\n      continue;\r\n    }\r\n    if (recordType !== 0) continue;\r\n\r\n    const fullAddr = extAddr + address;\r\n    const data = line.slice(9, 9 + byteCount * 2);\r\n\r\n    for (let i = 0; i < byteCount; i++) {\r\n      const byte = parseInt(data.slice(i * 2, i * 2 + 2), 16);\r\n      memory.set(fullAddr + i, byte);\r\n    }\r\n  }\r\n\r\n  const addresses = [...memory.keys()];\r\n  const maxAddr = Math.max(...addresses);\r\n  const fullArray = new Uint8Array(maxAddr + 1); \/\/ Desde 0 hasta maxAddr\r\n\r\n  for (let [addr, value] of memory.entries()) {\r\n    fullArray[addr] = value;\r\n  }\r\n\r\n  return fullArray.buffer;\r\n}\r\n\r\n\r\n\r\n    function binToHex(binArray) {\r\n      const lines = [];\r\n      const chunkSize = 16;\r\n      let upperAddress = -1;\r\n\r\n      for (let addr = 0; addr < binArray.length; addr += chunkSize) {\r\n        const chunk = binArray.slice(addr, addr + chunkSize);\r\n        const len = chunk.length;\r\n        const lowAddr = addr & 0xFFFF;\r\n        const highAddr = addr >> 16;\r\n\r\n        if (highAddr !== upperAddress) {\r\n          upperAddress = highAddr;\r\n          const extAddrLine = `02000004${highAddr.toString(16).padStart(4, '0').toUpperCase()}`;\r\n          const checksum = calculateChecksum([0x02, 0x00, 0x00, 0x04, highAddr >> 8, highAddr & 0xFF]);\r\n          lines.push(`:${extAddrLine}${checksum}`);\r\n        }\r\n\r\n        let line = `:${len.toString(16).padStart(2, '0').toUpperCase()}`;\r\n        line += lowAddr.toString(16).padStart(4, '0').toUpperCase();\r\n        line += '00'; \/\/ Record type\r\n\r\n        let checksum = len + (lowAddr >> 8) + (lowAddr & 0xFF);\r\n        let dataStr = '';\r\n        for (let byte of chunk) {\r\n          dataStr += byte.toString(16).padStart(2, '0').toUpperCase();\r\n          checksum += byte;\r\n        }\r\n\r\n        checksum = ((~checksum + 1) & 0xFF).toString(16).padStart(2, '0').toUpperCase();\r\n        lines.push(`${line}${dataStr}${checksum}`);\r\n      }\r\n\r\n      lines.push(':00000001FF'); \/\/ End Of File\r\n      return lines.join('\\n');\r\n    }\r\n\r\n    function calculateChecksum(bytes) {\r\n      const sum = bytes.reduce((acc, b) => acc + b, 0);\r\n      return ((~sum + 1) & 0xFF).toString(16).padStart(2, '0').toUpperCase();\r\n    }\r\n\r\n    function downloadFile(content, name, type) {\r\n      const blob = content instanceof Uint8Array\r\n        ? new Blob([content], { type })\r\n        : new Blob([content], { type });\r\n\r\n      const a = document.createElement('a');\r\n      a.href = URL.createObjectURL(blob);\r\n      a.download = name;\r\n      a.click();\r\n      URL.revokeObjectURL(a.href);\r\n    }\r\n  <\/script>\r\n<\/body>\r\n<\/html>\r\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>Convertidor HEX \u21c4 BIN Convertidor HEX \u21c4 BIN Sube tu archivo HEX\/BIN<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_acf_changed":false,"site-sidebar-layout":"no-sidebar","site-content-layout":"page-builder","ast-site-content-layout":"full-width-container","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"disabled","ast-breadcrumbs-content":"","ast-featured-img":"disabled","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"class_list":["post-3886","page","type-page","status-publish","hentry"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/dumpflashedit.com\/index.php\/wp-json\/wp\/v2\/pages\/3886","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dumpflashedit.com\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/dumpflashedit.com\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/dumpflashedit.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dumpflashedit.com\/index.php\/wp-json\/wp\/v2\/comments?post=3886"}],"version-history":[{"count":19,"href":"https:\/\/dumpflashedit.com\/index.php\/wp-json\/wp\/v2\/pages\/3886\/revisions"}],"predecessor-version":[{"id":3964,"href":"https:\/\/dumpflashedit.com\/index.php\/wp-json\/wp\/v2\/pages\/3886\/revisions\/3964"}],"wp:attachment":[{"href":"https:\/\/dumpflashedit.com\/index.php\/wp-json\/wp\/v2\/media?parent=3886"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}