The code below is the code I used last semster to turn decimal format intergers into hex, now is there a way I can reverse this function, and have it turn hex into dec.
Also the reason it is in a function format is we were studying funtions at the time of the assignment.

void displayHex(int pval)
     {
          int idiv,irmdr;
          irmdr=pval%16;
          idiv = pval/16;
          if (idiv>0) displayHex(idiv);
          if (irmdr<=9)
          cout<<irmdr;
                    else if (irmdr==10)
                         cout<<'A';
                    else if (irmdr==11)
                         cout<<'B';
                    else if (irmdr==12)
                         cout<<'C';
                    else if (irmdr==13)
                         cout<<'D';
                    else if (irmdr==14)
                         cout<<'E';
                    else if (irmdr==15)
                         cout<<'F';      
                         return;
     }

Recommended Answers

All 3 Replies

What have you tried so far?

You may want to learn some about bitwise operators as well, bit reading makes converting from hex to decimal and back again easy as pie.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.