Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to Convert To and From Hexadecimal Numbers Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
31-May-03
Category
Algorithm
Language
Delphi 3.x
Views
122
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Daniel Wischnewski

I have seen quite a few articles on how to convert a decimal number to 
hexa-decimal, yet none have used the most obviuos function. Delphi offers the 
solution already!

Answer:

The solution is quite simple. 

If you have an Integer intX and you want to convert it into an hexadecimal number 
use IntToHex(intNumber, intDigits) 

Expample 1: 
1   
2   strHex = IntToHex(intX, 2);


Delphi will create a hexadecimal string representing intX with at least two digits. 
Therefore if intX is 10, strHex will Hold 0A. 

To convert back to decimal you can use either StrToInt or StrToIntDef. However, you 
must ensure that the string contains a leading dollar-sign ($). 

Example 2.1 (Completting this article using Example 1): 
3   
4   intX = StrToInt('$' + strHex);


Delphi will take strHex (0A), you may have to provide the leading $ and will return 
the Decimal Value 10. 

Example 2.2 (Completting this article using Example 1): 
5   
6   intX = StrToIntDef('$' + strHex, -1);


Delphi will take strHex (0A), you may have to provide the leading $ and will return the Decimal Value 10. If the function fails, it will return the pre-defined value -1. 

			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC