Friday, April 10, 2020

HEXTODEC.P

[Table of Contents]
HEXTODEC.ATR Disk Image

HEXTODEC.P is from the Scalar Variables section of the Kyan Pascal 2.x manual/tutorial.

What's on the disk?


The disk image includes the various Atari DOS 2.5 files, Kyan Pascal Include files (none of which are used in this program), Kyan Pascal Run-time library, and ...

HEXTODEC.P - Source code file
P.OUT - Kyan Pascal intermediate file
HEXTODEC - Executable file

Source Code


(* HexToDec.p *)
(* Kyan Pascal 2.x / Atari 8-bit *)

Program HexToDec(Input,Output);

Type
   YesNo = (Yes, No);

Var
   Digit, Signal : Char;
   Number, OldNumber : Integer;
   Answer : YesNo; (* a scalar variable *)
   Continue : Boolean;

Begin

   OldNumber := 0;
   Writeln('Enter the most significant digit');
   Write('i.e. the one the begins on the far left.');
   Readln(Digit);

   Repeat (* Start of the REPEAT loop *)
      Case Digit Of (* Start the CASE list which takes the Digit
                       and finds its decimal equivalent *)
         '0' : Number := 0;
         '1' : Number := 1;
         '2' : Number := 2;
         '3' : Number := 3;
         '4' : Number := 4;
         '5' : Number := 5;
         '6' : Number := 6;
         '7' : Number := 7;
         '8' : Number := 8;
         '9' : Number := 9;
         'A' : Number := 10;
         'B' : Number := 11;
         'C' : Number := 12;
         'D' : Number := 13;
         'E' : Number := 14;
         'F' : Number := 15;
      End; (* of the CASE list *)

      OldNumber := Number + OldNumber * 16;
      Writeln;
      Writeln('Is there another digit');
      Writeln('after this one? (Yes or No) ');
      Readln(Signal);

      If (Signal = 'Y') Or (Signal = 'y') Then
         Answer := Yes
      Else
         Answer := No;

      If Answer = Yes Then 
         Begin
            Continue := True;
            Write('Enter the next digit ');
            Readln(Digit)
         End
      Else
         Begin
            Continue := False
         End;
   Until Not(Continue);
  
   Writeln;
   Writeln;
   Writeln('The decimal equivalent is ', OldNumber:6);
End.

Sample Run







No comments:

Post a Comment