Unix Shell - Hex to decimal replacement

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > December 2007 > Hex to decimal replacement





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Hex to decimal replacement
Tim Frink

2007-12-21, 7:33 am

Hi,

I've a C source code file which contains an array used as
input for a benchmark. The array look like that (contains
in reality over 60000 elements):

float a[] = {0x80, 0x43, 0x14 };

For some technical reasons, I'd like to covert these hex values
to their corresponding decimal numbers resulting in an array:

float a[] = {128, 67, 24 };

How could I do that with a script?

Regards,
Tim
Stephane Chazelas

2007-12-21, 7:33 am

On Fri, 21 Dec 2007 10:00:27 +0100, Tim Frink wrote:
> Hi,
>
> I've a C source code file which contains an array used as
> input for a benchmark. The array look like that (contains
> in reality over 60000 elements):
>
> float a[] = {0x80, 0x43, 0x14 };
>
> For some technical reasons, I'd like to covert these hex values
> to their corresponding decimal numbers resulting in an array:
>
> float a[] = {128, 67, 20 };

[...]

perl -pe 's/0x([0-9a-f]+)/hex$1/ige' < file

--
Stephane
Tim Frink

2007-12-21, 7:33 am

On Fri, 21 Dec 2007 09:52:22 +0000, Stephane Chazelas wrote:

> PERL -pe 's/0x([0-9a-f]+)/hex$1/ige' < file


Wow, thank you. ;-)

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2009 webservertalk.com