File tree 2 files changed +50
-0
lines changed
2 files changed +50
-0
lines changed Original file line number Diff line number Diff line change
1
+ def convert (num ):
2
+ """
3
+ Converte um número decimal para binário.
4
+
5
+ Args:
6
+ num: O número decimal a ser convertido.
7
+
8
+ Returns:
9
+ Uma lista de bits binários.
10
+ """
11
+
12
+ if num == 0 :
13
+ return [0 ]
14
+
15
+ binary = []
16
+ while num > 0 :
17
+ binary .append (num % 2 )
18
+ num //= 2
19
+
20
+ return binary [::- 1 ]
Original file line number Diff line number Diff line change
1
+ def toBinary (n ):
2
+ """
3
+ Converte um número decimal para binário.
4
+
5
+ Args:
6
+ n: O número decimal a ser convertido.
7
+
8
+ Returns:
9
+ Um único número binário.
10
+ """
11
+
12
+ if n == 0 :
13
+ return 0
14
+
15
+ bin = []
16
+ while n > 0 :
17
+ bin .append (n % 2 )
18
+ n //= 2
19
+
20
+ return int ("" .join ([str (x ) for x in bin [::- 1 ]]), 2 )
21
+
22
+
23
+ def main ():
24
+ n = int (input ("Digite um número decimal: " ))
25
+
26
+ print (f"O número binário de { n } é: { toBinary (n )} " )
27
+
28
+
29
+ if __name__ == "__main__" :
30
+ main ()
You can’t perform that action at this time.
0 commit comments