## Hex to Decimal conversion

Frequent Contributor
Posts: 79

# Hex to Decimal conversion

Could somebody please suggest me an idea....

We have Raw data which is being read and an variable MCL is getting created using \$CHAR8. format and then when I print it with Format \$HEX16. get below values...

MCL

----------

0008001E0001000F

00080015000000A3

0008001E0001000F

00080015000000A3

0008001E0001000F

00080015000000A3

0008001E0001000F

00080015000000A3

0008001E0001000F

Now each byte need to be converted in the format    AA.BB.CC.DDDD format so for example if we take 0008 it will be 8 ,001E=30,0001=1,000F=15

so equivalent of hex value 0008001E0001000F should be 8.30.1.15   ....Could somebody suggest me how we do that?

Super User
Posts: 10,280

## Re: Hex to Decimal conversion

Quick brute force attack:

data _null_;

length result \$20;

x = input('0008001E0001000F',\$hex16.);

xh = put(x,\$hex16.);

x1 = input(substr(xh,1,4),hex4.);

x2 = input(substr(xh,5,4),hex4.);

x3 = input(substr(xh,9,4),hex4.);

x4 = input(substr(xh,13,4),hex4.);

result = compress(put(x1,best5.)!!'.'!!put(x2,best5.)!!'.'!!put(x3,best5.)!!'.'!!put(x4,best5.));

put result=;

run;

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Discussion stats