Created
April 4, 2013 11:06
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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