Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Compile and Execute Pascal Online

Program HelloWorld(output);
{$MODE Delphi}

uses
  SysUtils;

////////////////////////////////////////////////////////////////////////////////
function IntToLetters(Number: Cardinal): string;
var
  Modulo: Cardinal;
begin
  Result := '';
  while (Number > 0) do begin
    Modulo := (Number - 1) mod 26;
    Result := Char(65 + Modulo) + Result;
    Number := (Number - Modulo) div 26;
  end;
end {IntToLetters};

////////////////////////////////////////////////////////////////////////////////
function LettersToInt(Letters: string): Cardinal;
var
  i: Integer;
begin
  Letters := UpperCase(Letters);

  Result := 0;
  for i := 1 to Length(Letters) do begin
    Result := Result * 26;
    Inc(Result, Ord(Letters[i]) - 64);
  end;
end {LettersToInt};

procedure TestValue(const i: Integer);
var
  IL: string;
  ILI: Integer;
begin
  Write(i, #9);
  IL := IntToLetters(i);
  Write(IL, #9);
  ILI := LettersToInt(IntToLetters(i)); 
  WriteLn(ILI);
  Assert(i = ILI);
end;


var
  i: Integer;
begin
  for i := 0 to 1024 do begin
    TestValue(i);
  end;
  TestValue(16383);
  TestValue(16384);
  TestValue(16385);
  TestValue(65535);
  TestValue(65536);
  TestValue(65537);
end.

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.