Files
HexPigeon/frontend/src/utils/hex.ts
T
delikesanceandCursor 71974f5107 Add WASM parser and Vue dissector UI.
Ship a working HexPigeon: typed binary parsing in Rust/WASM, a three-pane frontend, and unit tests covering the field types.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-03 16:26:52 +00:00

18 lines
605 B
TypeScript

/** Parse a hex dump string into byte values. Whitespace is ignored. */
export function parseHexInput(hex: string): number[] {
const clean = hex.replace(/\s/g, '')
if (clean.length % 2 !== 0) return []
const out: number[] = []
for (let i = 0; i < clean.length; i += 2) {
const b = parseInt(clean.slice(i, i + 2), 16)
if (Number.isNaN(b)) return []
out.push(b)
}
return out
}
/** Format bytes as uppercase hex pairs separated by spaces. */
export function formatHexBytes(bytes: number[]): string {
return bytes.map(b => b.toString(16).padStart(2, '0').toUpperCase()).join(' ')
}