0

Good Evening to all..
Can someone help with regards to converting decimal to hexadecimal?
I'm using stack.
I am done. in doing Dec to binary and Decimal to Octal.
My problem is how to convert decimal to hex? specially if its include now with letters A to D..

pls i really need ur answers or suggestions.. here is my code for converting dec to hex.

System.out.print("Enter a Decimal Value:");
                num=console.nextInt();
                 q=num;
                while(true)
           {
               s.push(q%16);
               q=q/16;
               
               if(q==0)
               break;
            }
            System.out.print("HexaDecimal equivalent");
            while(!s.isEmpty())
            {
                
             System.out.print(s.pop());
            }

my problem is that.. how about if the pop value is 10? basically it should be converted into letter A. but how to do that? pls me... i really need to finish my program.. :(

Edited by Nick Evan: Added CODE-tags

2
Contributors
5
Replies
7
Views
7 Years
Discussion Span
Last Post by JamesCherrill
0

I assume you have an int in the range 0 -15, so the clean way to do it is to have an arrray of chars, initilised to '0' ... 'F' and use the int as an index into this array.

0

sir, can you give me psuedocode for it pls? so that i can understand it very well

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.