converting char to 16-bit hexadecimal and decimal


I need a function which will take a string(can be a phrase) and convert each character of it into 16-bit hexa-decimal and decimal.

For example, each character's hexa-decimal and decimal values :
Char                       decimal                          16-bit  hexa-decimal
t            t                      t
e                             e                                 e
s                             s                                 s
t                             t                                 t
i                            i                               i
n                           n                      n
g                           g                                g

when the string 'testing'  is passed to the function the output should be as follows:
decimal:  testing
hexa-decimal: testing

The string can be a phrase with spaces/underscores/special characters in between like 'testing purpose only'/testing for ____ days'.......

Any help regarding the same would be grateful....

Thanks a lot!!!
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

The underlying value is the same in each case. The only thing that is changing is the way it is being represented in the output. That is, if a variable contains decimal 116, it can variously be output as 't', 116 or 0x74.

So a conversion routine would look something like this:

String convert(String src,int radix)
{   StringBuffer sb=new StringBuffer(src.length*6);
    for(int i=0; i<src.length; ++i)
    {   sb.append("&#");

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mayank SPrincipal TechnologistCommented:
The decimal value for a character can directly be obtained using ( int ) c, where 'c' is a character.
Did any of that help?

If so, it is now time to select an answer(s) and grade it.

If not, perhaps a clarifying question would help.
dreams4everAuthor Commented:
Hi imladris

It did work......was able to check it out only today.....

Thanks a lot!!

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.