Skip to content

Instantly share code, notes, and snippets.

@tuankiet65
Created April 4, 2013 11:06
Show Gist options
  • Save tuankiet65/5309535 to your computer and use it in GitHub Desktop.
Save tuankiet65/5309535 to your computer and use it in GitHub Desktop.
Nhập một số, đổi ra hệ nhị phân và bát phân
program binary_and_octal;
uses crt;
var input: int64;
function string_reverse(s: ansistring): ansistring;
var i: longint;
begin
for i:=length(s) downto 1 do string_reverse:=string_reverse+s[i];
end;
function decimalto(n, x: longint): ansistring;
var tmp: string;
begin
while n<>0 do begin
str(n mod x, tmp);
decimalto:=decimalto+tmp;
n:=n div x;
end;
decimalto:=string_reverse(decimalto);
end;
begin
clrscr;
write('Nhap so: ');
readln(input);
writeln('Nhi phan: ', decimalto(input, 2));
write('Bat phan: ', decimalto(input, 8));
readkey;
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment