Converting hex to dec, from .txt file (but problem)

Hey guys, i'm doing program for converting hexadecimal to decade numbers, that is not problem, but i have some hex numbers in .txt files like this:

[b]hex.txt[/b]
[code]0xCCF
0X13AFB
0x34FA[/code]

i have wrote some procedures to load that hex files:

[code]program Data(input,output);
type

TXT_DATOTEKA = text;

var
i,j:integer;
POCETNA_DATOTEKA : TXT_DATOTEKA;
ZNAK_D:CHAR;
IME_DATOTEKE:string;


procedure UCITAJ_DATOTEKU(var IME_UL_DATOTEKE:string);
begin
write('Unesite ime ulazne datoteke: ');
read(IME_UL_DATOTEKE);
end;

procedure ISPISI_DATOTEKU(var DATOTEKA:TXT_DATOTEKA;ZNAK:CHAR;IME:STRING);
begin

assign(DATOTEKA,IME);
reset(DATOTEKA);
writeln;
writeln('** Ulazna datoteka sadrzi sledece podatke: **');
writeln;
while not eof(DATOTEKA) do
begin
read(DATOTEKA,ZNAK);
write(output,ZNAK);
end;
end;

begin

UCITAJ_DATOTEKU(IME_DATOTEKE);

ISPISI_DATOTEKU(POCETNA_DATOTEKA,ZNAK_D,IME_DATOTEKE);

readln;


end.[/code]

This code load all files from hex.txt...QUESTION IS:
How can I remove this two first chars [b]0x[/b] to work only with hex numbers, and what is best way to convert this numbers, to store them to array and than to make procedure with loop in array to convert?



Comments

  • : This code load all files from hex.txt...QUESTION IS:
    : How can I remove this two first chars [b]0x[/b] to work only with
    : hex numbers, and what is best way to convert this numbers, to store
    : them to array and than to make procedure with loop in array to
    : convert?
    :

    To remove the [b]0x[/b] use: s:=copy(s,3,length(s)-2); , that will strip the first 2 character from a string. To convert the hexadecimals to decimal numbers just read on, there were quite a few posts regarding this subject.

  • What is S?string or text?I have defined my txt data in pascal like text, you can see code...So I think Length(text) wont work in pascal?
  • : What is S?string or text?I have defined my txt data in pascal like
    : text, you can see code...So I think Length(text) wont work in pascal?
    :

    [b]s[/b] is string, and texts consist of strings separated by the CR+LF (#13#10) pairs.
  • This post has been deleted.
  • an you give me an example on my code, how to remove [b]0x[/b]?
    Do I need to write procedure or ?
  • : an you give me an example on my code, how to remove [b]0x[/b]?
    : Do I need to write procedure or ?
    :

    If you could translate it, I might be able to help...
  • I think, that I have figured how to solve problem, thnx anyway.
  • This post has been deleted.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories