Converting from decimal to hex

A

Anders Bystrup

Hi.

I have an array consisting of mac addresses in decimal form seperated by :
Like this:
0:0:33:195:37:6 0:0:180:75:15:17 and so on

I now need to convert the decimal numbers into hex on the following form:
00:e0:98:9b:ce:6f 00:e0:98:a4:db:41

Is it possible to do this using a search and replace or how would you do
this?

/Anders
 
J

John J. Trammell

Hi.

I have an array consisting of mac addresses in decimal form seperated by :
Like this:
0:0:33:195:37:6 0:0:180:75:15:17 and so on

I now need to convert the decimal numbers into hex on the following form:
00:e0:98:9b:ce:6f 00:e0:98:a4:db:41

Is it possible to do this using a search and replace or how would you do
this?

One solution:

s/(\d+)/sprintf("%02x",$1)/eg;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top