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!

Hex to decimal

Status
Not open for further replies.

664950

Programmer
Aug 27, 2001
28
BA
How to get decimal value of hex var? I don't understand how to use StrToInt function
 
ok ,here is a function that does what you need

function HexToInt(HexString:String):Integer;
begin
result:=StrToIntDef('$'+HexString,0);
end;
 
Hi people.
I needed to extract bytes from a file content. So i used following code (using earlrainer function above). I used FileRead and got 2500 bytes into Buffer.

var
aHex : array[0..100] of Char;
S : String;
:
:
FileSeek(iHandle,0,0);
Buffer := PChar(AllocMem(2501));
iRead := FileRead(iHandle, Buffer^, 2500);
S := Buffer[3]+Buffer[4]+Buffer[1]+Buffer[2];
aHex := ' ';
BinToHex(PChar(S),aHex,4);
if StrToIntDef('$'+aHex,0) <> 1024 then
// Something Wrong;

Machine suddenly uses least significant bytes and words first. This is because I read bytes 3 and 4 and after 1 and 2. I need 1024 from $00000400 that is the same thing in different notation. My question is : there´s a easiest way to do this ?

Besides, in other portion I need to compare 50 bytes with a string like this :
S := '';
for iRead := 2048 to 2097 do
S := S + Buffer[iRead];
if S <> 'SOMESTRING' then
// Something wrong too.
Here, I used a FOR loop. Copy(Buffer,2048,50) didn´t work.
Is there a easiest way too to do this ?
Tks in advance.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top