Chương trình Chuyển hệ thập phân sang hệ 16


Chuyển hệ thập phân sang hệ 16

Program Thap_Phan_To_16;
uses
SysUtils;

const
BASE16 = 16;
var
HexValue : string;
Remainder : Integer;
Quotient : Integer;
begin
HexValue := ”;
write( ‘CHO BIET SO THAP PHAN CAN CHUYEN DOI: ‘ );
readln( Quotient );
while Quotient > 0 do
begin
Remainder := Quotient mod BASE16;
case Remainder of
10: HexValue := ‘A’ + HexValue;
11: HexValue := ‘B’ + HexValue;
12: HexValue := ‘C’ + HexValue;
13: HexValue := ‘D’ + HexValue;
14: HexValue := ‘E’ + HexValue;
15: HexValue := ‘F’ + HexValue;
else
HexValue := IntToStr( Remainder ) + HexValue;
End;
Quotient := Quotient div BASE16
end;
writeln;
writeln( HexValue );
writeln;
End.