0

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;
     }
4
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by Red Goose
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.