3

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

3 Answers 3

1

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

3
  • -1 for just posting a link. This is a place for collecting knowledge, what happens if the link dies?
    – Nifle
    Commented Jul 7, 2011 at 23:47
  • 1
    @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)
    – stanigator
    Commented Jul 8, 2011 at 7:41
3

.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%
0

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:

68edcdec4e2c8eae8d2c8e2dedcd6e04d2042fedae52ceac04 ccedaecd8c042ccd8c046cedad0e8dac8eac8c048e0dac044a a82889046c0d2c8d8daccdecacc5042bedae4e04ee2dcd046c

./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!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .