# Converting a series of bytes from hexadecimal numbers into decimal numbers

Is there an app/script out there that can convert a series of bytes from hex to dec (if not, is there an easy way to achieve this in the command prompt in a few lines)?

``````03 01 9d f0 b4 05 01 67 40 20 00 6b ad
``````

There are tons of online converters, like this one: http://home2.paulschou.net/tools/xlate/

• -1 for just posting a link. This is a place for collecting knowledge, what happens if the link dies? Commented Jul 7, 2011 at 23:47
• @Nifle Use one of the thousands of others out there? The OP didn't ask for a lesson on Hexadecimal mathematics, just a one-off conversion. Commented Jul 8, 2011 at 0:06
• @Amazed: I think Nifle meant ones similar to the link you've included, but these thousands of others would be suffice (didn't know the keywords to search for them properly originally) Commented Jul 8, 2011 at 7:41

`.js` script for `cscript`:

``````num = [];
for (i = 0; i < WScript.Arguments.Length; i++) {
arg = WScript.Arguments(i);
num.push(parseInt(arg, 16));
}
WScript.Echo(num.join(" "));
``````

Batch script for `cmd.exe`:

``````@echo off & setlocal
set /a out=0x%1
:loop
if "%~1"=="" goto :end
set /a num=0x%1
set out=%out% %num%
shift
goto :loop
:end
echo.%out%
``````

If all you want is a string of hex to a string of decimal, then this tiny perl program will do it:

``````#!/usr/bin/perl
while(<>){s/(.\s*.)\s*/hex(\$1).' '/eg;print;}
``````

input.hex:

``````./hex2dec.pl < input.hex
``````

It's forgiving about white space in the source and only looks for consecutive pairs of hex digits.

Just modify with sprintf, push, split etc to control output format

If you install perl on windows, then this will work on the command line:

``````perl -e "while(<>){s/(.\s*.)\s*/hex(\$1).' '/eg;print;}" < input.hex
``````

Perl is amazing. Noone should be without it!