Program Breakdown;

{ This program takes a hexidecimal number from 0 -> $ffff & breaks it down
  into smaller byte size numbers }

const hexidec : array[0..15] of char='0123456789ABCDEF';

type breakint = record
      case integer of
       1 : (bigint : integer);
       2 : (smlint1, smlint2 : byte);
      end;
     str2 = string[2];

Function Hex(mynum : byte) : str2;
 var value1, value3 : real;
     value2         : integer;
     dummy          : str2;

begin
 value1:=mynum/16;
 value2:=trunc(value1);
 dummy:=hexidec[value2];
 value3:=value1-value2;
 value3:=value3*16;
 value2:=trunc(value3);
 dummy:=dummy+hexidec[value2];
 hex:=dummy;
end;

var num1 : breakint;
    num2 : integer;

begin
 clrscr;
 write('Enter Integer Number:');
 {$I-}readln(num2);{$I+}
 while (IOResult<>0) do
  begin
   writeln;
   writeln('Please enter a value between $0 or $ffff');
   writeln('Your only making this hard on yourself');
   write('if you''re not doing the right thing:');
   {$I-}readln(num2);{$I+}
  end;
 num1.bigint:=num2;
 writeln('The High Value of this is:',hex(num1.smlint2));
 writeln('The Low Value of this is:',hex(num1.smlint1));
end.
