Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bin, Hex, ASCII...

Status
Not open for further replies.

UmaGrama

Technical User
Sep 8, 2003
33
BR
Hello,

My question is: how can I display a number in another base (hex, bin) without having it converted to decimal when it is compiled?

Thanks :D
 
Number is always stored in memory in binary format. So compille does not convert the to decimal. To any bases you could convert only the human readable string which repersents your number.

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
So you are saying that I would have to convert it myself and turn it into a string?
 
To print out a value as hex it's only nessecary to give the format parameter as %X in stead of %u (or %d).

To print a value as binary you need to make a routine to convert it.

Totte
 
it should eb something like this pseudocode:

xx = 0x4D2;//the hex representation of 1234
temp = xx;
base = ...;
result = "";
while(temp != 0)
{
temp -= last;
temp /= base;
last = temp % base;
result = temp concat to result;
}
cout<< result<< endl;


Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top