Convert entire file from HEX to DEC in Batch, Python or VBS -
i have been researching hours, cannot figure out how convert file "hex.txt" (with hex in it) "dec.txt"(decimal).
hex.txt has bunch of hex values this:
0x0000: 0a 00 00 08 00 06 61 75 74 68 6f 72 0x000c: 00 09 41 6e 6f 6e 79 6d 6f 75 73 09 0x0018: 00 06 62 6c 6f 63 6b 73 0a 00 00 01 0x0024: 5a 09 00 03 70 6f 73 03 00 00 00 03
and want convert decimal batch, vbs or python. appreciated.
a batch solution (why other languages in title no tags?).
- the command
set /a
convert hex values decimal if prefixed0x
- so need
for /f
split lines @ colon address , values , simplefor
process each value. - setting , using values inside (code block) requires delayedexpansion
> type hex2dec.cmd @echo off & setlocal enabledelayedexpansion /f "tokens=1* delims=:" %%a in (hex.txt) ( set /a decaddr=%%a set "decaddr= !decaddr!" set "dec=" %%c in (%%b) ( set /a dec#=0x%%c set "dec#= !dec#!" set dec=!dec!!dec#:~-4! ) echo !decaddr:~-5!: !dec! )
sample output:
> hex2dec.cmd 0: 10 0 0 8 0 6 97 117 116 104 111 114 12: 0 9 65 110 111 110 121 109 111 117 115 9 24: 0 6 98 108 111 99 107 115 10 0 0 1 36: 90 9 0 3 112 111 115 3 0 0 0 3
Comments
Post a Comment