-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvertor.pas
More file actions
83 lines (71 loc) · 1.47 KB
/
convertor.pas
File metadata and controls
83 lines (71 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
Program convertor ;
// Programa que converte um numero decimal em seu binario, hexadecimal e octal respectivo
var
decimal : integer;
// binario
quociente, i, resto : integer;
binario : string;
strresto : string;
// hexadecimal
hexa : string;
// octal
octal : string;
Begin
// receber um numero decimal
write('Digite um numero decimal: ');
readln(decimal);
writeln();
quociente := decimal;
binario := '';
// binario
repeat
resto := quociente MOD 2;
quociente := trunc(quociente / 2);
str(resto:1,strresto);
binario := concat(strresto,binario);
until (quociente = 0);
writeln('binario: ', binario);
writeln('---');
// hexadecimal
quociente := decimal;
hexa := '';
repeat
resto := quociente MOD 16;
quociente := trunc(quociente / 16);
case resto of
10 : begin
hexa := concat('A', hexa);
end;
11 : begin
hexa := concat('B', hexa);
end;
12 : begin
hexa := concat('C', hexa);
end;
13 : begin
hexa := concat('D', hexa);
end;
14 : begin
hexa := concat('E', hexa);
end;
15 : begin
hexa := concat('F', hexa);
end;
else
str(resto:1,strresto);
hexa := concat(strresto,hexa);
end;
until (quociente = 0);
writeln('hexa: ', hexa);
writeln('---');
// octal
quociente := decimal;
octal := '';
repeat
resto := quociente MOD 8;
quociente := trunc(quociente / 8);
str(resto:1,strresto);
octal := concat(strresto,octal);
until (quociente = 0);
writeln('octal: ', octal);
End.