Mega Code Archive

 
Categories / Delphi / Algorithm Math
 

Convert hex to dec

Title: Convert hex to dec Question: At times, in the manufacturing applications (and not only), you she can return profit a function that converts a hexadecimal value in decimal. Not you forget to insert in the USESs "math." Answer: function HEX_to_DEC(Value: string): Int64; var Lunghezza, i : Byte; ValoreDEC: Int64; Value2 : string; begin Result := 0; for i := 1 to Length( Value ) do Value2 := Value[ i ] + Value2; Value := Value2; for Lunghezza := Length(Value) - 1 downto 0 do begin ValoreDEC := Pos(Value[Lunghezza +1],'0123456789ABCDEF')-1; if (ValoreDEC 15) then begin ShowMessage('Valore inserito non valido'); Result := 0; exit; end; Result := Result + ValoreDEC shl (4 * Lunghezza); end; end;