Page 1 of 1

Reputation:

convert Hex number to decimal and vice versa

Posted 14 April 2010 - 04:40 PM

Write a program that able to convert Hex number to decimal and vice versa. The program should have two functions. The first function called hexToDec takes one argument as string and returns an integer. The second function called decToHex takes also one argument as integer and returns a string. The program should offer the user two options:

1. To convert Hex to Dec.
2. To convert Dec to Hex.

Example:
Please choose one of the following:
1- Convert Hex to Dec. 2- Convert Dec to Hex.
1 Please enter a Hex number: 2A 2A = 42 in Decimal.

====================================
Please choose one of the following:
1- Convert Hex to Dec. 2- Convert Dec to Hex.
2 Please enter a Dec number: 2748 2748 = ABC in Hex.

Assume that all Letters are in capital letters so you do not need to worry about small letters too.

Is This A Good Question/Topic? 0

Replies To: convert Hex number to decimal and vice versa

#2 CTphpnwb

• D.I.C Lover

Reputation: 3798
• Posts: 13,755
• Joined: 08-August 08

Re: convert Hex number to decimal and vice versa

Posted 14 April 2010 - 05:00 PM

And what are you going to do?

Reputation:

Re: convert Hex number to decimal and vice versa

Posted 14 April 2010 - 05:14 PM

all what i meant i that i need help with this assignment ,, that's y i asked in the 1st place ?

#4 CTphpnwb

• D.I.C Lover

Reputation: 3798
• Posts: 13,755
• Joined: 08-August 08

Re: convert Hex number to decimal and vice versa

Posted 14 April 2010 - 05:18 PM

Sigh. Try reading the rules.

#5 Aphex19

• Born again Pastafarian.

Reputation: 619
• Posts: 1,873
• Joined: 02-August 09

Re: convert Hex number to decimal and vice versa

Posted 14 April 2010 - 05:49 PM

Just show us what you have done and what you know so far.

#6 college_trained

• New D.I.C Head

Reputation: 1
• Posts: 49
• Joined: 10-January 10

Re: convert Hex number to decimal and vice versa

Posted 14 April 2010 - 06:16 PM

I think what they are trying to say is show the effort you've put into this assignment so far. The contributors here are not here to do your homework for you. They will help if you are having trouble with something though.
My suggestion is, if you don't already know how to convert between the two on paper, learn that first. If you do know how to, then write down the process in which you would convert step-by-step. Then start coding from there.
I think this is a great assignment as I have been working on this type thing but on a bigger scale (converting between Binary, Octal, Decimal, and Hex) all in one program.

Reputation:

Re: convert Hex number to decimal and vice versa

Posted 24 April 2010 - 12:16 PM

strstream can be handy.Just check it out.Specifically look for the manipulators like hex and octa.

#8 jjl

• Engineer

Reputation: 1270
• Posts: 4,998
• Joined: 09-June 09

Re: convert Hex number to decimal and vice versa

Posted 24 April 2010 - 12:21 PM

take a look at std::hex
```	cout<<std::hex<<15<<endl;

```