# keidan/hex2bin architecture

> Architecture diagram of the GitHub repository keidan/hex2bin, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/keidan/hex2bin
- Repository: https://github.com/keidan/hex2bin

## Overview

hex2bin is a command-line converter for plain hexadecimal text and Intel HEX files. Users select input/output files and conversion options; the CLI validates the files, dispatches to the selected conversion mode, and writes the result. Intel HEX mode supports conversion in both directions, including address and padding options documented in the README. The graph separates CLI dispatch, conversion stages, and shared file/helper code. Some implementation details are unsampled, so only documented or excerpt-visible relationships are connected.

Main entry points: [`src/h2b/utils/Files.cpp`](https://github.com/keidan/hex2bin/blob/master/src/h2b/utils/Files.cpp) (File streams), [`src/main.cpp`](https://github.com/keidan/hex2bin/blob/master/src/main.cpp) (CLI dispatch), [`src/h2b/IntelHex.cpp`](https://github.com/keidan/hex2bin/blob/master/src/h2b/IntelHex.cpp) (Intel HEX coordinator), [`src/h2b/Hex2Bin.cpp`](https://github.com/keidan/hex2bin/blob/master/src/h2b/Hex2Bin.cpp) (Hex text conversion)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["CLI"]
  node_cli["CLI dispatch<br/>[main.cpp]"]
  node_winopts["Windows options<br/>[getopt_long.c]"]
end

subgraph group_conversion["Conversion"]
  node_hextext["Hex text conversion<br/>[Hex2Bin.cpp]"]
  node_ihex["Intel HEX coordinator<br/>[IntelHex.cpp]"]
  node_ihexbin["Intel HEX to binary<br/>[Intel2Bin.cpp]"]
  node_binihex["Binary to Intel HEX<br/>[Bin2Intel.cpp]"]
end

subgraph group_shared["Shared I/O"]
  node_files["File streams<br/>[Files.cpp]"]
  node_helpers["Conversion helpers<br/>[Helper.hpp]"]
end

node_user(("CLI user"))
node_input["Input file"]
node_output["Output file"]

node_user -->|"supplies options"| node_cli
node_cli -->|"dispatches"| node_hextext
node_cli -->|"dispatches"| node_ihex
node_cli -->|"includes on Windows"| node_winopts
node_ihex -->|"delegates conversion"| node_ihexbin
node_ihex -->|"delegates conversion"| node_binihex
node_hextext -->|"uses parsing helpers"| node_helpers
node_ihexbin -->|"uses parsing helpers"| node_helpers
node_binihex -->|"uses record helpers"| node_helpers
node_ihex -->|"shares file access"| node_files
node_hextext -->|"reads and writes"| node_files
node_ihexbin -->|"reads and writes"| node_files
node_binihex -->|"reads and writes"| node_files
node_input -.->|"opened as input"| node_files
node_files -.->|"writes result"| node_output

click node_cli "https://github.com/keidan/hex2bin/blob/master/src/main.cpp"
click node_winopts "https://github.com/keidan/hex2bin/blob/master/src/win32/getopt_long.c"
click node_hextext "https://github.com/keidan/hex2bin/blob/master/src/h2b/Hex2Bin.cpp"
click node_ihex "https://github.com/keidan/hex2bin/blob/master/src/h2b/IntelHex.cpp"
click node_ihexbin "https://github.com/keidan/hex2bin/blob/master/src/h2b/ihex/Intel2Bin.cpp"
click node_binihex "https://github.com/keidan/hex2bin/blob/master/src/h2b/ihex/Bin2Intel.cpp"
click node_files "https://github.com/keidan/hex2bin/blob/master/src/h2b/utils/Files.cpp"
click node_helpers "https://github.com/keidan/hex2bin/blob/master/src/h2b/utils/Helper.hpp"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli,node_winopts,node_user toneBlue
class node_hextext,node_ihex,node_ihexbin,node_binihex toneAmber
class node_files,node_helpers toneMint
class node_input,node_output toneIndigo
```

## Components

### CLI

- [CLI dispatch](https://github.com/keidan/hex2bin/blob/master/src/main.cpp): `src/main.cpp`
- [Windows options](https://github.com/keidan/hex2bin/blob/master/src/win32/getopt_long.c): `src/win32/getopt_long.c`

### Conversion

- [Hex text conversion](https://github.com/keidan/hex2bin/blob/master/src/h2b/Hex2Bin.cpp): `src/h2b/Hex2Bin.cpp`
- [Intel HEX coordinator](https://github.com/keidan/hex2bin/blob/master/src/h2b/IntelHex.cpp): `src/h2b/IntelHex.cpp`
- [Intel HEX to binary](https://github.com/keidan/hex2bin/blob/master/src/h2b/ihex/Intel2Bin.cpp): `src/h2b/ihex/Intel2Bin.cpp`
- [Binary to Intel HEX](https://github.com/keidan/hex2bin/blob/master/src/h2b/ihex/Bin2Intel.cpp): `src/h2b/ihex/Bin2Intel.cpp`

### Shared I/O

- [File streams](https://github.com/keidan/hex2bin/blob/master/src/h2b/utils/Files.cpp): `src/h2b/utils/Files.cpp`
- [Conversion helpers](https://github.com/keidan/hex2bin/blob/master/src/h2b/utils/Helper.hpp): `src/h2b/utils/Helper.hpp`

### Other components

- **CLI user**
- **Input file**
- **Output file**

## Connections

- CLI user → CLI dispatch: supplies options (evidence: `README.md`)
- CLI dispatch → Hex text conversion: dispatches (evidence: `src/main.cpp`)
- CLI dispatch → Intel HEX coordinator: dispatches (evidence: `src/main.cpp`)
- CLI dispatch → Windows options: includes on Windows (evidence: `src/main.cpp`)
- Intel HEX coordinator → Intel HEX to binary: delegates conversion (evidence: `src/h2b/IntelHex.cpp`)
- Intel HEX coordinator → Binary to Intel HEX: delegates conversion (evidence: `src/h2b/IntelHex.cpp`)
- Hex text conversion → Conversion helpers: uses parsing helpers (evidence: `src/h2b/Hex2Bin.cpp`)
- Intel HEX to binary → Conversion helpers: uses parsing helpers (evidence: `src/h2b/ihex/Intel2Bin.cpp`)
- Binary to Intel HEX → Conversion helpers: uses record helpers (evidence: `src/h2b/ihex/Bin2Intel.cpp`)
- Intel HEX coordinator → File streams: shares file access (evidence: `src/h2b/IntelHex.cpp`)
- Hex text conversion → File streams: reads and writes (evidence: `src/h2b/Hex2Bin.cpp`)
- Intel HEX to binary → File streams: reads and writes (evidence: `src/h2b/ihex/Intel2Bin.cpp`)
- Binary to Intel HEX → File streams: reads and writes (evidence: `src/h2b/ihex/Bin2Intel.cpp`)
- Input file → File streams: opened as input
- File streams → Output file: writes result
