FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Basic-Python-Programs/GrayCodetoBinary.py at Test · gitishman/Basic-Python-Programs · GitHub
gitishman
/
Basic-Python-Programs
Public
forked from
souravjain540/Basic-Python-Programs
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Basic-Python-Programs
/
GrayCodetoBinary.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
37 lines (26 loc) · 833 Bytes
Breadcrumbs
Basic-Python-Programs
/
GrayCodetoBinary.py
Copy path
File metadata and controls
37 lines (26 loc) · 833 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
def
flip_num
(
my_nu
):
return
'1'
if
(
my_nu
==
'0'
)
else
'0'
;
def
gray_to_binary
(
gray
):
binary_code
=
""
binary_code
+=
gray
[
0
]
for
i
in
range
(
1
,
len
(
gray
)):
if
(
gray
[
i
]
==
'0'
):
binary_code
+=
binary_code
[
i
-
1
]
else
:
binary_code
+=
flip_num
(
binary_code
[
i
-
1
])
return
binary_code
# gray_code="01101001"
gray_code
=
input
(
"please enter the gray code
\n
"
)
print
(
"the gray code is : "
)
print
(
gray_code
)
# x=gray_to_binary(gray_code)
print
(
"binary code of"
,
gray_code
,
"is"
,
gray_to_binary
(
gray_code
))
# for converting binary numb to decimal
value
=
0
b_num
=
list
(
gray_to_binary
(
gray_code
))
for
i
in
range
(
len
(
b_num
)):
digit
=
b_num
.
pop
()
if
digit
==
'1'
:
value
=
value
+
pow
(
2
,
i
)
print
(
"the decimal value of the number is "
,
value
)
# print(12//5)
Back
|
FazBrowse Home
|
New Git URL